All of lore.kernel.org
 help / color / mirror / Atom feed
* [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-07-22 21:24 ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

This RFC v3 builds off the last RFC v2 series [0] for adding linker tables.
The largest amount of work here was to take Russell King's feedback on
using linker table for kprobes text not being appropriate -- and providing
another lightweight API for simple section ranges: read-only stitched pieces
of executable code. This required also generalizing common building blocks
for both linker tables and section ranges, these building blocks are defined
now in include/linux/sections.h and asm-generic/section.h. The other last thing
decided was to not support sub-sections. In the hunt for this I could think of
anything that really required this, and if it was needed it did not seem
impossible to port over to avoid its use. Please let me know if there are valid
uses cases for sub-sections.

Other significant effort here was to provide a set of common assembly helpers
which could be used across architectures, this starts off some of this work
for generic helpers which carve out and define custom Linux sections.

Lastly, this now also goes with two ports which required module support when
using linker tables: jump labels, and dynamic debug support. A few
extensions have been made to the original series in order to provide
support for that.

Since kprobes actually had both a linker table and a section range the
patch that dealt with kprobes is now split off in two patches, one
that deals with its linker table and another for its section ranges.

More elaborate uses for linker tables are possible, I'll hold off on any
of this type of work until at least the basic building blocks are fleshed
out. To review how this work came about, and more elaborate uses being
evaluated check out the userspace linker-tables mockup solution [1].
Hopefully most of the possible bikeshedding was already dealt with through
that tree. Thanks to hpa for tons of feedback.

Should you need it, the code here is also available on my linux-next
20160722-linker-table-v3-try2 branch on kernel.org [2]. Lastly, ranges and
table development go under copyleft-next, Rusty recently asked for code
to go in prior to the license tag being added denoting this license as
GPL-compatible [3] -- I had noted in the patch submission which annotated
copyleft-next's compatibility to GPLv2 that copyleft-next is the license
of choice for ongoing kernel development on my end [4]. If this is
objectionable I'm happy to change it to GPLv2 however I'd like a reason
provided as I've gone through all possible channels to ensure this is kosher,
including vetting by 3 attorneys now, 2 at SUSE.

This all goes tested by 0-day... however since I found an issue with linker
tables and blackfin this series remains as RFC -- I'll try to debug the
issue with Steven Miao. The issue with blackfin is using a config that
enables CONFIG_FW_LOADER=y and CONFIG_DYNAMIC_DEBUG=y [5] we end up with
the following at final link time:

  LD      init/built-in.o
lib/built-in.o: In function `dynamic_debug_init':
lib/dynamic_debug.c:(.init.text+0x156): undefined reference to `__verbose__end'
lib/dynamic_debug.c:(.init.text+0x15a): undefined reference to `__verbose__end'
lib/dynamic_debug.c:(.init.text+0x160): undefined reference to `__verbose'
lib/dynamic_debug.c:(.init.text+0x164): undefined reference to `__verbose'
lib/dynamic_debug.c:(.init.text+0x214): undefined reference to `__verbose__end'
lib/dynamic_debug.c:(.init.text+0x218): undefined reference to `__verbose__end'
lib/dynamic_debug.c:(.init.text+0x252): undefined reference to `__verbose__end'
lib/dynamic_debug.c:(.init.text+0x258): undefined reference to `__verbose'
lib/dynamic_debug.c:(.init.text+0x25c): undefined reference to `__verbose__end'
lib/dynamic_debug.c:(.init.text+0x260): undefined reference to `__verbose'
drivers/built-in.o: In function `release_firmware':
(.text+0x22dc2): undefined reference to `builtin_fw'
drivers/built-in.o: In function `release_firmware':
(.text+0x22dc6): undefined reference to `builtin_fw__end'
drivers/built-in.o: In function `release_firmware':
(.text+0x22dca): undefined reference to `builtin_fw'
drivers/built-in.o: In function `release_firmware':
(.text+0x22dce): undefined reference to `builtin_fw__end'
drivers/built-in.o: In function `fw_get_builtin_firmware':
drivers/base/firmware_class.c:(.text+0x23008): undefined reference to `builtin_fw'
drivers/base/firmware_class.c:(.text+0x2300c): undefined reference to `builtin_fw__end'
drivers/base/firmware_class.c:(.text+0x23010): undefined reference to `builtin_fw'
drivers/base/firmware_class.c:(.text+0x23014): undefined reference to `builtin_fw__end'
Makefile:957: recipe for target 'vmlinux' failed
make: *** [vmlinux] Error 1

To reproduce then:

wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
wget http://drvbp1.linux-foundation.org/~mcgrof/2016/07/22/blackfin-fw-dyndbg.config -o .config
make.cross ARCH=blackfin

[0] https://lkml.kernel.org/r/1455889559-9428-1-git-send-email-mcgrof@kernel.org
[1] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linker-tables.git/
[2] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linux-next.git/log/?h 160722-linker-table-v3-try2
[3] https://lkml.kernel.org/r/87y44zhbiu.fsf@rustcorp.com.au
[4] https://lkml.kernel.org/r/1467327207-14916-1-git-send-email-mcgrof@kernel.org
[5] http://drvbp1.linux-foundation.org/~mcgrof/2016/07/22/blackfin-fw-dyndbg.config


Luis R. Rodriguez (13):
  x86: remove LTO_REFERENCE_INITCALL()
  dell-smo8800: include uaccess.h
  scripts/module-common.lds: enable generation
  sections.h: guard against asm and linker script
  sections.h: add sections header to collect all section info
  ranges.h: add helpers to build and identify Linux section ranges
  tables.h: add linker table support
  firmware/Makefile: force recompilation if makefile changes
  firmware: port built-in section to linker table
  jump_label: port __jump_table to linker tables
  dynamic_debug: port to use linker tables
  kprobes: port .kprobes.text to section range
  kprobes: port blacklist kprobes to linker table

 .gitignore                                         |   2 +
 Documentation/DocBook/Makefile                     |   3 +-
 Documentation/DocBook/linker-tables.tmpl           | 166 ++++++
 Documentation/DocBook/sections.tmpl                | 112 ++++
 Documentation/kbuild/makefiles.txt                 |  19 +
 Makefile                                           |   6 +-
 arch/alpha/include/asm/ranges.h                    |   6 +
 arch/alpha/include/asm/sections.h                  |   6 +
 arch/alpha/include/asm/tables.h                    |   6 +
 arch/arc/include/asm/ranges.h                      |   6 +
 arch/arc/include/asm/tables.h                      |   6 +
 arch/arc/kernel/vmlinux.lds.S                      |   1 -
 arch/arm/include/asm/jump_label.h                  |   6 +-
 arch/arm/include/asm/ranges.h                      |   6 +
 arch/arm/include/asm/sections.h                    |   2 +
 arch/arm/include/asm/tables.h                      |   6 +
 arch/arm/kernel/entry-armv.S                       |   3 +-
 arch/arm/kernel/vmlinux-xip.lds.S                  |   1 -
 arch/arm/kernel/vmlinux.lds.S                      |   1 -
 arch/arm64/include/asm/jump_label.h                |   6 +-
 arch/arm64/include/asm/ranges.h                    |   6 +
 arch/arm64/include/asm/sections.h                  |   6 +
 arch/arm64/include/asm/tables.h                    |   6 +
 arch/avr32/include/asm/ranges.h                    |   6 +
 arch/avr32/include/asm/sections.h                  |   6 +
 arch/avr32/include/asm/tables.h                    |   6 +
 arch/avr32/kernel/entry-avr32b.S                   |   5 +-
 arch/avr32/kernel/vmlinux.lds.S                    |   1 -
 arch/blackfin/include/asm/ranges.h                 |   6 +
 arch/blackfin/include/asm/sections.h               |   4 +
 arch/blackfin/include/asm/tables.h                 |   6 +
 arch/blackfin/kernel/vmlinux.lds.S                 |   1 -
 arch/c6x/include/asm/ranges.h                      |   6 +
 arch/c6x/include/asm/tables.h                      |   6 +
 arch/c6x/kernel/vmlinux.lds.S                      |   1 -
 arch/cris/include/asm/ranges.h                     |   6 +
 arch/cris/include/asm/sections.h                   |   6 +
 arch/cris/include/asm/tables.h                     |   6 +
 arch/frv/include/asm/ranges.h                      |   6 +
 arch/frv/include/asm/tables.h                      |   6 +
 arch/h8300/include/asm/ranges.h                    |   6 +
 arch/h8300/include/asm/sections.h                  |   6 +
 arch/h8300/include/asm/tables.h                    |   6 +
 arch/hexagon/include/asm/ranges.h                  |   6 +
 arch/hexagon/include/asm/sections.h                |   6 +
 arch/hexagon/include/asm/tables.h                  |   6 +
 arch/hexagon/kernel/vmlinux.lds.S                  |   1 -
 arch/ia64/include/asm/ranges.h                     |   6 +
 arch/ia64/include/asm/sections.h                   |   7 +-
 arch/ia64/include/asm/tables.h                     |   6 +
 arch/ia64/kernel/jprobes.S                         |   3 +-
 arch/ia64/kernel/vmlinux.lds.S                     |   1 -
 arch/ia64/lib/flush.S                              |   5 +-
 arch/m32r/include/asm/ranges.h                     |   6 +
 arch/m32r/include/asm/sections.h                   |   6 +
 arch/m32r/include/asm/tables.h                     |   6 +
 arch/m68k/include/asm/ranges.h                     |   6 +
 arch/m68k/include/asm/sections.h                   |   6 +
 arch/m68k/include/asm/tables.h                     |   6 +
 arch/metag/include/asm/ranges.h                    |   6 +
 arch/metag/include/asm/sections.h                  |   6 +
 arch/metag/include/asm/tables.h                    |   6 +
 arch/metag/kernel/vmlinux.lds.S                    |   1 -
 arch/microblaze/include/asm/ranges.h               |   6 +
 arch/microblaze/include/asm/tables.h               |   6 +
 arch/microblaze/kernel/vmlinux.lds.S               |   1 -
 arch/mips/include/asm/jump_label.h                 |   6 +-
 arch/mips/include/asm/ranges.h                     |   6 +
 arch/mips/include/asm/sections.h                   |   6 +
 arch/mips/include/asm/tables.h                     |   6 +
 arch/mips/kernel/vmlinux.lds.S                     |   1 -
 arch/mn10300/include/asm/ranges.h                  |   6 +
 arch/mn10300/include/asm/sections.h                |   6 +
 arch/mn10300/include/asm/tables.h                  |   6 +
 arch/mn10300/kernel/vmlinux.lds.S                  |   1 -
 arch/nios2/include/asm/ranges.h                    |   6 +
 arch/nios2/include/asm/sections.h                  |   6 +
 arch/nios2/include/asm/tables.h                    |   6 +
 arch/nios2/kernel/vmlinux.lds.S                    |   1 -
 arch/openrisc/include/asm/ranges.h                 |   6 +
 arch/openrisc/include/asm/sections.h               |   6 +
 arch/openrisc/include/asm/tables.h                 |   6 +
 arch/openrisc/kernel/vmlinux.lds.S                 |   1 -
 arch/parisc/include/asm/ranges.h                   |   6 +
 arch/parisc/include/asm/tables.h                   |   6 +
 arch/parisc/kernel/vmlinux.lds.S                   |   1 -
 arch/powerpc/include/asm/jump_label.h              |   8 +-
 arch/powerpc/include/asm/ppc_asm.h                 |   7 +-
 arch/powerpc/include/asm/ranges.h                  |   6 +
 arch/powerpc/include/asm/sections.h                |  11 +-
 arch/powerpc/include/asm/tables.h                  |   6 +
 arch/powerpc/kernel/vmlinux.lds.S                  |   1 -
 arch/s390/include/asm/jump_label.h                 |   6 +-
 arch/s390/include/asm/ranges.h                     |   6 +
 arch/s390/include/asm/tables.h                     |   6 +
 arch/s390/kernel/entry.S                           |   5 +-
 arch/s390/kernel/kprobes.c                         |   6 +-
 arch/s390/kernel/mcount.S                          |   2 +-
 arch/s390/kernel/vmlinux.lds.S                     |   1 -
 arch/score/include/asm/ranges.h                    |   6 +
 arch/score/include/asm/sections.h                  |   6 +
 arch/score/include/asm/tables.h                    |   6 +
 arch/score/kernel/vmlinux.lds.S                    |   1 -
 arch/sh/include/asm/ranges.h                       |   6 +
 arch/sh/include/asm/sections.h                     |   2 +
 arch/sh/include/asm/tables.h                       |   6 +
 arch/sh/kernel/vmlinux.lds.S                       |   1 -
 arch/sparc/include/asm/jump_label.h                |   6 +-
 arch/sparc/include/asm/ranges.h                    |   6 +
 arch/sparc/include/asm/sections.h                  |   4 +
 arch/sparc/include/asm/tables.h                    |   6 +
 arch/sparc/kernel/vmlinux.lds.S                    |   1 -
 arch/sparc/mm/ultra.S                              |   3 +-
 arch/tile/include/asm/ranges.h                     |   6 +
 arch/tile/include/asm/sections.h                   |   4 +
 arch/tile/include/asm/tables.h                     |   6 +
 arch/tile/kernel/vmlinux.lds.S                     |   1 -
 arch/um/include/asm/ranges.h                       |   6 +
 arch/um/include/asm/tables.h                       |   6 +
 arch/unicore32/include/asm/ranges.h                |   6 +
 arch/unicore32/include/asm/sections.h              |   6 +
 arch/unicore32/include/asm/tables.h                |   6 +
 arch/x86/include/asm/jump_label.h                  |  10 +-
 arch/x86/include/asm/ranges.h                      |   6 +
 arch/x86/include/asm/sections.h                    |  23 +-
 arch/x86/include/asm/tables.h                      |   6 +
 arch/x86/include/asm/uaccess.h                     |  18 +-
 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                            |   3 +
 arch/xtensa/include/asm/ranges.h                   |   6 +
 arch/xtensa/include/asm/sections.h                 |   6 +
 arch/xtensa/include/asm/tables.h                   |   6 +
 drivers/base/firmware_class.c                      |  12 +-
 drivers/platform/x86/dell-smo8800.c                |   1 +
 firmware/Makefile                                  |   7 +-
 include/asm-generic/ranges.h                       |  70 +++
 include/asm-generic/sections.h                     | 306 ++++++++++-
 include/asm-generic/tables.h                       |  70 +++
 include/asm-generic/vmlinux.lds.h                  |  66 +--
 include/linux/compiler.h                           |   2 +-
 include/linux/dynamic_debug.h                      |   5 +-
 include/linux/init.h                               |  20 +-
 include/linux/jump_label.h                         |  10 +-
 include/linux/kprobes.h                            |   8 +-
 include/linux/ranges.h                             |  54 ++
 include/linux/sections.h                           | 123 +++++
 include/linux/tables.h                             | 597 +++++++++++++++++++++
 kernel/jump_label.c                                |  17 +-
 kernel/kprobes.c                                   |  17 +-
 lib/dynamic_debug.c                                |  13 +-
 scripts/Makefile                                   |   1 +
 scripts/Makefile.build                             |   4 +-
 scripts/Makefile.clean                             |   1 +
 scripts/Makefile.lib                               |  12 +
 scripts/Makefile.modpost                           |   2 +-
 scripts/mod/Makefile                               |   2 +
 scripts/mod/modpost.c                              |   8 +-
 scripts/{module-common.lds => module-common.lds.S} |   6 +
 scripts/recordmcount.c                             |   7 +-
 scripts/recordmcount.pl                            |   2 +-
 tools/include/linux/sections.h                     |  13 +
 tools/objtool/special.c                            |   8 +-
 164 files changed, 2241 insertions(+), 205 deletions(-)
 create mode 100644 Documentation/DocBook/linker-tables.tmpl
 create mode 100644 Documentation/DocBook/sections.tmpl
 create mode 100644 arch/alpha/include/asm/ranges.h
 create mode 100644 arch/alpha/include/asm/sections.h
 create mode 100644 arch/alpha/include/asm/tables.h
 create mode 100644 arch/arc/include/asm/ranges.h
 create mode 100644 arch/arc/include/asm/tables.h
 create mode 100644 arch/arm/include/asm/ranges.h
 create mode 100644 arch/arm/include/asm/tables.h
 create mode 100644 arch/arm64/include/asm/ranges.h
 create mode 100644 arch/arm64/include/asm/sections.h
 create mode 100644 arch/arm64/include/asm/tables.h
 create mode 100644 arch/avr32/include/asm/ranges.h
 create mode 100644 arch/avr32/include/asm/sections.h
 create mode 100644 arch/avr32/include/asm/tables.h
 create mode 100644 arch/blackfin/include/asm/ranges.h
 create mode 100644 arch/blackfin/include/asm/tables.h
 create mode 100644 arch/c6x/include/asm/ranges.h
 create mode 100644 arch/c6x/include/asm/tables.h
 create mode 100644 arch/cris/include/asm/ranges.h
 create mode 100644 arch/cris/include/asm/sections.h
 create mode 100644 arch/cris/include/asm/tables.h
 create mode 100644 arch/frv/include/asm/ranges.h
 create mode 100644 arch/frv/include/asm/tables.h
 create mode 100644 arch/h8300/include/asm/ranges.h
 create mode 100644 arch/h8300/include/asm/sections.h
 create mode 100644 arch/h8300/include/asm/tables.h
 create mode 100644 arch/hexagon/include/asm/ranges.h
 create mode 100644 arch/hexagon/include/asm/sections.h
 create mode 100644 arch/hexagon/include/asm/tables.h
 create mode 100644 arch/ia64/include/asm/ranges.h
 create mode 100644 arch/ia64/include/asm/tables.h
 create mode 100644 arch/m32r/include/asm/ranges.h
 create mode 100644 arch/m32r/include/asm/sections.h
 create mode 100644 arch/m32r/include/asm/tables.h
 create mode 100644 arch/m68k/include/asm/ranges.h
 create mode 100644 arch/m68k/include/asm/sections.h
 create mode 100644 arch/m68k/include/asm/tables.h
 create mode 100644 arch/metag/include/asm/ranges.h
 create mode 100644 arch/metag/include/asm/sections.h
 create mode 100644 arch/metag/include/asm/tables.h
 create mode 100644 arch/microblaze/include/asm/ranges.h
 create mode 100644 arch/microblaze/include/asm/tables.h
 create mode 100644 arch/mips/include/asm/ranges.h
 create mode 100644 arch/mips/include/asm/sections.h
 create mode 100644 arch/mips/include/asm/tables.h
 create mode 100644 arch/mn10300/include/asm/ranges.h
 create mode 100644 arch/mn10300/include/asm/sections.h
 create mode 100644 arch/mn10300/include/asm/tables.h
 create mode 100644 arch/nios2/include/asm/ranges.h
 create mode 100644 arch/nios2/include/asm/sections.h
 create mode 100644 arch/nios2/include/asm/tables.h
 create mode 100644 arch/openrisc/include/asm/ranges.h
 create mode 100644 arch/openrisc/include/asm/sections.h
 create mode 100644 arch/openrisc/include/asm/tables.h
 create mode 100644 arch/parisc/include/asm/ranges.h
 create mode 100644 arch/parisc/include/asm/tables.h
 create mode 100644 arch/powerpc/include/asm/ranges.h
 create mode 100644 arch/powerpc/include/asm/tables.h
 create mode 100644 arch/s390/include/asm/ranges.h
 create mode 100644 arch/s390/include/asm/tables.h
 create mode 100644 arch/score/include/asm/ranges.h
 create mode 100644 arch/score/include/asm/sections.h
 create mode 100644 arch/score/include/asm/tables.h
 create mode 100644 arch/sh/include/asm/ranges.h
 create mode 100644 arch/sh/include/asm/tables.h
 create mode 100644 arch/sparc/include/asm/ranges.h
 create mode 100644 arch/sparc/include/asm/tables.h
 create mode 100644 arch/tile/include/asm/ranges.h
 create mode 100644 arch/tile/include/asm/tables.h
 create mode 100644 arch/um/include/asm/ranges.h
 create mode 100644 arch/um/include/asm/tables.h
 create mode 100644 arch/unicore32/include/asm/ranges.h
 create mode 100644 arch/unicore32/include/asm/sections.h
 create mode 100644 arch/unicore32/include/asm/tables.h
 create mode 100644 arch/x86/include/asm/ranges.h
 create mode 100644 arch/x86/include/asm/tables.h
 create mode 100644 arch/xtensa/include/asm/ranges.h
 create mode 100644 arch/xtensa/include/asm/sections.h
 create mode 100644 arch/xtensa/include/asm/tables.h
 create mode 100644 include/asm-generic/ranges.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%)
 create mode 100644 tools/include/linux/sections.h

-- 
2.8.4


^ permalink raw reply	[flat|nested] 176+ messages in thread

* [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-07-22 21:24 ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

This RFC v3 builds off the last RFC v2 series [0] for adding linker tables.
The largest amount of work here was to take Russell King's feedback on
using linker table for kprobes text not being appropriate -- and providing
another lightweight API for simple section ranges: read-only stitched pieces
of executable code. This required also generalizing common building blocks
for both linker tables and section ranges, these building blocks are defined
now in include/linux/sections.h and asm-generic/section.h. The other last thing
decided was to not support sub-sections. In the hunt for this I could think of
anything that really required this, and if it was needed it did not seem
impossible to port over to avoid its use. Please let me know if there are valid
uses cases for sub-sections.

Other significant effort here was to provide a set of common assembly helpers
which could be used across architectures, this starts off some of this work
for generic helpers which carve out and define custom Linux sections.

Lastly, this now also goes with two ports which required module support when
using linker tables: jump labels, and dynamic debug support. A few
extensions have been made to the original series in order to provide
support for that.

Since kprobes actually had both a linker table and a section range the
patch that dealt with kprobes is now split off in two patches, one
that deals with its linker table and another for its section ranges.

More elaborate uses for linker tables are possible, I'll hold off on any
of this type of work until at least the basic building blocks are fleshed
out. To review how this work came about, and more elaborate uses being
evaluated check out the userspace linker-tables mockup solution [1].
Hopefully most of the possible bikeshedding was already dealt with through
that tree. Thanks to hpa for tons of feedback.

Should you need it, the code here is also available on my linux-next
20160722-linker-table-v3-try2 branch on kernel.org [2]. Lastly, ranges and
table development go under copyleft-next, Rusty recently asked for code
to go in prior to the license tag being added denoting this license as
GPL-compatible [3] -- I had noted in the patch submission which annotated
copyleft-next's compatibility to GPLv2 that copyleft-next is the license
of choice for ongoing kernel development on my end [4]. If this is
objectionable I'm happy to change it to GPLv2 however I'd like a reason
provided as I've gone through all possible channels to ensure this is kosher,
including vetting by 3 attorneys now, 2 at SUSE.

This all goes tested by 0-day... however since I found an issue with linker
tables and blackfin this series remains as RFC -- I'll try to debug the
issue with Steven Miao. The issue with blackfin is using a config that
enables CONFIG_FW_LOADER=y and CONFIG_DYNAMIC_DEBUG=y [5] we end up with
the following at final link time:

  LD      init/built-in.o
lib/built-in.o: In function `dynamic_debug_init':
lib/dynamic_debug.c:(.init.text+0x156): undefined reference to `__verbose__end'
lib/dynamic_debug.c:(.init.text+0x15a): undefined reference to `__verbose__end'
lib/dynamic_debug.c:(.init.text+0x160): undefined reference to `__verbose'
lib/dynamic_debug.c:(.init.text+0x164): undefined reference to `__verbose'
lib/dynamic_debug.c:(.init.text+0x214): undefined reference to `__verbose__end'
lib/dynamic_debug.c:(.init.text+0x218): undefined reference to `__verbose__end'
lib/dynamic_debug.c:(.init.text+0x252): undefined reference to `__verbose__end'
lib/dynamic_debug.c:(.init.text+0x258): undefined reference to `__verbose'
lib/dynamic_debug.c:(.init.text+0x25c): undefined reference to `__verbose__end'
lib/dynamic_debug.c:(.init.text+0x260): undefined reference to `__verbose'
drivers/built-in.o: In function `release_firmware':
(.text+0x22dc2): undefined reference to `builtin_fw'
drivers/built-in.o: In function `release_firmware':
(.text+0x22dc6): undefined reference to `builtin_fw__end'
drivers/built-in.o: In function `release_firmware':
(.text+0x22dca): undefined reference to `builtin_fw'
drivers/built-in.o: In function `release_firmware':
(.text+0x22dce): undefined reference to `builtin_fw__end'
drivers/built-in.o: In function `fw_get_builtin_firmware':
drivers/base/firmware_class.c:(.text+0x23008): undefined reference to `builtin_fw'
drivers/base/firmware_class.c:(.text+0x2300c): undefined reference to `builtin_fw__end'
drivers/base/firmware_class.c:(.text+0x23010): undefined reference to `builtin_fw'
drivers/base/firmware_class.c:(.text+0x23014): undefined reference to `builtin_fw__end'
Makefile:957: recipe for target 'vmlinux' failed
make: *** [vmlinux] Error 1

To reproduce then:

wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
wget http://drvbp1.linux-foundation.org/~mcgrof/2016/07/22/blackfin-fw-dyndbg.config -o .config
make.cross ARCH=blackfin

[0] https://lkml.kernel.org/r/1455889559-9428-1-git-send-email-mcgrof@kernel.org
[1] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linker-tables.git/
[2] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linux-next.git/log/?h=20160722-linker-table-v3-try2
[3] https://lkml.kernel.org/r/87y44zhbiu.fsf@rustcorp.com.au
[4] https://lkml.kernel.org/r/1467327207-14916-1-git-send-email-mcgrof@kernel.org
[5] http://drvbp1.linux-foundation.org/~mcgrof/2016/07/22/blackfin-fw-dyndbg.config


Luis R. Rodriguez (13):
  x86: remove LTO_REFERENCE_INITCALL()
  dell-smo8800: include uaccess.h
  scripts/module-common.lds: enable generation
  sections.h: guard against asm and linker script
  sections.h: add sections header to collect all section info
  ranges.h: add helpers to build and identify Linux section ranges
  tables.h: add linker table support
  firmware/Makefile: force recompilation if makefile changes
  firmware: port built-in section to linker table
  jump_label: port __jump_table to linker tables
  dynamic_debug: port to use linker tables
  kprobes: port .kprobes.text to section range
  kprobes: port blacklist kprobes to linker table

 .gitignore                                         |   2 +
 Documentation/DocBook/Makefile                     |   3 +-
 Documentation/DocBook/linker-tables.tmpl           | 166 ++++++
 Documentation/DocBook/sections.tmpl                | 112 ++++
 Documentation/kbuild/makefiles.txt                 |  19 +
 Makefile                                           |   6 +-
 arch/alpha/include/asm/ranges.h                    |   6 +
 arch/alpha/include/asm/sections.h                  |   6 +
 arch/alpha/include/asm/tables.h                    |   6 +
 arch/arc/include/asm/ranges.h                      |   6 +
 arch/arc/include/asm/tables.h                      |   6 +
 arch/arc/kernel/vmlinux.lds.S                      |   1 -
 arch/arm/include/asm/jump_label.h                  |   6 +-
 arch/arm/include/asm/ranges.h                      |   6 +
 arch/arm/include/asm/sections.h                    |   2 +
 arch/arm/include/asm/tables.h                      |   6 +
 arch/arm/kernel/entry-armv.S                       |   3 +-
 arch/arm/kernel/vmlinux-xip.lds.S                  |   1 -
 arch/arm/kernel/vmlinux.lds.S                      |   1 -
 arch/arm64/include/asm/jump_label.h                |   6 +-
 arch/arm64/include/asm/ranges.h                    |   6 +
 arch/arm64/include/asm/sections.h                  |   6 +
 arch/arm64/include/asm/tables.h                    |   6 +
 arch/avr32/include/asm/ranges.h                    |   6 +
 arch/avr32/include/asm/sections.h                  |   6 +
 arch/avr32/include/asm/tables.h                    |   6 +
 arch/avr32/kernel/entry-avr32b.S                   |   5 +-
 arch/avr32/kernel/vmlinux.lds.S                    |   1 -
 arch/blackfin/include/asm/ranges.h                 |   6 +
 arch/blackfin/include/asm/sections.h               |   4 +
 arch/blackfin/include/asm/tables.h                 |   6 +
 arch/blackfin/kernel/vmlinux.lds.S                 |   1 -
 arch/c6x/include/asm/ranges.h                      |   6 +
 arch/c6x/include/asm/tables.h                      |   6 +
 arch/c6x/kernel/vmlinux.lds.S                      |   1 -
 arch/cris/include/asm/ranges.h                     |   6 +
 arch/cris/include/asm/sections.h                   |   6 +
 arch/cris/include/asm/tables.h                     |   6 +
 arch/frv/include/asm/ranges.h                      |   6 +
 arch/frv/include/asm/tables.h                      |   6 +
 arch/h8300/include/asm/ranges.h                    |   6 +
 arch/h8300/include/asm/sections.h                  |   6 +
 arch/h8300/include/asm/tables.h                    |   6 +
 arch/hexagon/include/asm/ranges.h                  |   6 +
 arch/hexagon/include/asm/sections.h                |   6 +
 arch/hexagon/include/asm/tables.h                  |   6 +
 arch/hexagon/kernel/vmlinux.lds.S                  |   1 -
 arch/ia64/include/asm/ranges.h                     |   6 +
 arch/ia64/include/asm/sections.h                   |   7 +-
 arch/ia64/include/asm/tables.h                     |   6 +
 arch/ia64/kernel/jprobes.S                         |   3 +-
 arch/ia64/kernel/vmlinux.lds.S                     |   1 -
 arch/ia64/lib/flush.S                              |   5 +-
 arch/m32r/include/asm/ranges.h                     |   6 +
 arch/m32r/include/asm/sections.h                   |   6 +
 arch/m32r/include/asm/tables.h                     |   6 +
 arch/m68k/include/asm/ranges.h                     |   6 +
 arch/m68k/include/asm/sections.h                   |   6 +
 arch/m68k/include/asm/tables.h                     |   6 +
 arch/metag/include/asm/ranges.h                    |   6 +
 arch/metag/include/asm/sections.h                  |   6 +
 arch/metag/include/asm/tables.h                    |   6 +
 arch/metag/kernel/vmlinux.lds.S                    |   1 -
 arch/microblaze/include/asm/ranges.h               |   6 +
 arch/microblaze/include/asm/tables.h               |   6 +
 arch/microblaze/kernel/vmlinux.lds.S               |   1 -
 arch/mips/include/asm/jump_label.h                 |   6 +-
 arch/mips/include/asm/ranges.h                     |   6 +
 arch/mips/include/asm/sections.h                   |   6 +
 arch/mips/include/asm/tables.h                     |   6 +
 arch/mips/kernel/vmlinux.lds.S                     |   1 -
 arch/mn10300/include/asm/ranges.h                  |   6 +
 arch/mn10300/include/asm/sections.h                |   6 +
 arch/mn10300/include/asm/tables.h                  |   6 +
 arch/mn10300/kernel/vmlinux.lds.S                  |   1 -
 arch/nios2/include/asm/ranges.h                    |   6 +
 arch/nios2/include/asm/sections.h                  |   6 +
 arch/nios2/include/asm/tables.h                    |   6 +
 arch/nios2/kernel/vmlinux.lds.S                    |   1 -
 arch/openrisc/include/asm/ranges.h                 |   6 +
 arch/openrisc/include/asm/sections.h               |   6 +
 arch/openrisc/include/asm/tables.h                 |   6 +
 arch/openrisc/kernel/vmlinux.lds.S                 |   1 -
 arch/parisc/include/asm/ranges.h                   |   6 +
 arch/parisc/include/asm/tables.h                   |   6 +
 arch/parisc/kernel/vmlinux.lds.S                   |   1 -
 arch/powerpc/include/asm/jump_label.h              |   8 +-
 arch/powerpc/include/asm/ppc_asm.h                 |   7 +-
 arch/powerpc/include/asm/ranges.h                  |   6 +
 arch/powerpc/include/asm/sections.h                |  11 +-
 arch/powerpc/include/asm/tables.h                  |   6 +
 arch/powerpc/kernel/vmlinux.lds.S                  |   1 -
 arch/s390/include/asm/jump_label.h                 |   6 +-
 arch/s390/include/asm/ranges.h                     |   6 +
 arch/s390/include/asm/tables.h                     |   6 +
 arch/s390/kernel/entry.S                           |   5 +-
 arch/s390/kernel/kprobes.c                         |   6 +-
 arch/s390/kernel/mcount.S                          |   2 +-
 arch/s390/kernel/vmlinux.lds.S                     |   1 -
 arch/score/include/asm/ranges.h                    |   6 +
 arch/score/include/asm/sections.h                  |   6 +
 arch/score/include/asm/tables.h                    |   6 +
 arch/score/kernel/vmlinux.lds.S                    |   1 -
 arch/sh/include/asm/ranges.h                       |   6 +
 arch/sh/include/asm/sections.h                     |   2 +
 arch/sh/include/asm/tables.h                       |   6 +
 arch/sh/kernel/vmlinux.lds.S                       |   1 -
 arch/sparc/include/asm/jump_label.h                |   6 +-
 arch/sparc/include/asm/ranges.h                    |   6 +
 arch/sparc/include/asm/sections.h                  |   4 +
 arch/sparc/include/asm/tables.h                    |   6 +
 arch/sparc/kernel/vmlinux.lds.S                    |   1 -
 arch/sparc/mm/ultra.S                              |   3 +-
 arch/tile/include/asm/ranges.h                     |   6 +
 arch/tile/include/asm/sections.h                   |   4 +
 arch/tile/include/asm/tables.h                     |   6 +
 arch/tile/kernel/vmlinux.lds.S                     |   1 -
 arch/um/include/asm/ranges.h                       |   6 +
 arch/um/include/asm/tables.h                       |   6 +
 arch/unicore32/include/asm/ranges.h                |   6 +
 arch/unicore32/include/asm/sections.h              |   6 +
 arch/unicore32/include/asm/tables.h                |   6 +
 arch/x86/include/asm/jump_label.h                  |  10 +-
 arch/x86/include/asm/ranges.h                      |   6 +
 arch/x86/include/asm/sections.h                    |  23 +-
 arch/x86/include/asm/tables.h                      |   6 +
 arch/x86/include/asm/uaccess.h                     |  18 +-
 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                            |   3 +
 arch/xtensa/include/asm/ranges.h                   |   6 +
 arch/xtensa/include/asm/sections.h                 |   6 +
 arch/xtensa/include/asm/tables.h                   |   6 +
 drivers/base/firmware_class.c                      |  12 +-
 drivers/platform/x86/dell-smo8800.c                |   1 +
 firmware/Makefile                                  |   7 +-
 include/asm-generic/ranges.h                       |  70 +++
 include/asm-generic/sections.h                     | 306 ++++++++++-
 include/asm-generic/tables.h                       |  70 +++
 include/asm-generic/vmlinux.lds.h                  |  66 +--
 include/linux/compiler.h                           |   2 +-
 include/linux/dynamic_debug.h                      |   5 +-
 include/linux/init.h                               |  20 +-
 include/linux/jump_label.h                         |  10 +-
 include/linux/kprobes.h                            |   8 +-
 include/linux/ranges.h                             |  54 ++
 include/linux/sections.h                           | 123 +++++
 include/linux/tables.h                             | 597 +++++++++++++++++++++
 kernel/jump_label.c                                |  17 +-
 kernel/kprobes.c                                   |  17 +-
 lib/dynamic_debug.c                                |  13 +-
 scripts/Makefile                                   |   1 +
 scripts/Makefile.build                             |   4 +-
 scripts/Makefile.clean                             |   1 +
 scripts/Makefile.lib                               |  12 +
 scripts/Makefile.modpost                           |   2 +-
 scripts/mod/Makefile                               |   2 +
 scripts/mod/modpost.c                              |   8 +-
 scripts/{module-common.lds => module-common.lds.S} |   6 +
 scripts/recordmcount.c                             |   7 +-
 scripts/recordmcount.pl                            |   2 +-
 tools/include/linux/sections.h                     |  13 +
 tools/objtool/special.c                            |   8 +-
 164 files changed, 2241 insertions(+), 205 deletions(-)
 create mode 100644 Documentation/DocBook/linker-tables.tmpl
 create mode 100644 Documentation/DocBook/sections.tmpl
 create mode 100644 arch/alpha/include/asm/ranges.h
 create mode 100644 arch/alpha/include/asm/sections.h
 create mode 100644 arch/alpha/include/asm/tables.h
 create mode 100644 arch/arc/include/asm/ranges.h
 create mode 100644 arch/arc/include/asm/tables.h
 create mode 100644 arch/arm/include/asm/ranges.h
 create mode 100644 arch/arm/include/asm/tables.h
 create mode 100644 arch/arm64/include/asm/ranges.h
 create mode 100644 arch/arm64/include/asm/sections.h
 create mode 100644 arch/arm64/include/asm/tables.h
 create mode 100644 arch/avr32/include/asm/ranges.h
 create mode 100644 arch/avr32/include/asm/sections.h
 create mode 100644 arch/avr32/include/asm/tables.h
 create mode 100644 arch/blackfin/include/asm/ranges.h
 create mode 100644 arch/blackfin/include/asm/tables.h
 create mode 100644 arch/c6x/include/asm/ranges.h
 create mode 100644 arch/c6x/include/asm/tables.h
 create mode 100644 arch/cris/include/asm/ranges.h
 create mode 100644 arch/cris/include/asm/sections.h
 create mode 100644 arch/cris/include/asm/tables.h
 create mode 100644 arch/frv/include/asm/ranges.h
 create mode 100644 arch/frv/include/asm/tables.h
 create mode 100644 arch/h8300/include/asm/ranges.h
 create mode 100644 arch/h8300/include/asm/sections.h
 create mode 100644 arch/h8300/include/asm/tables.h
 create mode 100644 arch/hexagon/include/asm/ranges.h
 create mode 100644 arch/hexagon/include/asm/sections.h
 create mode 100644 arch/hexagon/include/asm/tables.h
 create mode 100644 arch/ia64/include/asm/ranges.h
 create mode 100644 arch/ia64/include/asm/tables.h
 create mode 100644 arch/m32r/include/asm/ranges.h
 create mode 100644 arch/m32r/include/asm/sections.h
 create mode 100644 arch/m32r/include/asm/tables.h
 create mode 100644 arch/m68k/include/asm/ranges.h
 create mode 100644 arch/m68k/include/asm/sections.h
 create mode 100644 arch/m68k/include/asm/tables.h
 create mode 100644 arch/metag/include/asm/ranges.h
 create mode 100644 arch/metag/include/asm/sections.h
 create mode 100644 arch/metag/include/asm/tables.h
 create mode 100644 arch/microblaze/include/asm/ranges.h
 create mode 100644 arch/microblaze/include/asm/tables.h
 create mode 100644 arch/mips/include/asm/ranges.h
 create mode 100644 arch/mips/include/asm/sections.h
 create mode 100644 arch/mips/include/asm/tables.h
 create mode 100644 arch/mn10300/include/asm/ranges.h
 create mode 100644 arch/mn10300/include/asm/sections.h
 create mode 100644 arch/mn10300/include/asm/tables.h
 create mode 100644 arch/nios2/include/asm/ranges.h
 create mode 100644 arch/nios2/include/asm/sections.h
 create mode 100644 arch/nios2/include/asm/tables.h
 create mode 100644 arch/openrisc/include/asm/ranges.h
 create mode 100644 arch/openrisc/include/asm/sections.h
 create mode 100644 arch/openrisc/include/asm/tables.h
 create mode 100644 arch/parisc/include/asm/ranges.h
 create mode 100644 arch/parisc/include/asm/tables.h
 create mode 100644 arch/powerpc/include/asm/ranges.h
 create mode 100644 arch/powerpc/include/asm/tables.h
 create mode 100644 arch/s390/include/asm/ranges.h
 create mode 100644 arch/s390/include/asm/tables.h
 create mode 100644 arch/score/include/asm/ranges.h
 create mode 100644 arch/score/include/asm/sections.h
 create mode 100644 arch/score/include/asm/tables.h
 create mode 100644 arch/sh/include/asm/ranges.h
 create mode 100644 arch/sh/include/asm/tables.h
 create mode 100644 arch/sparc/include/asm/ranges.h
 create mode 100644 arch/sparc/include/asm/tables.h
 create mode 100644 arch/tile/include/asm/ranges.h
 create mode 100644 arch/tile/include/asm/tables.h
 create mode 100644 arch/um/include/asm/ranges.h
 create mode 100644 arch/um/include/asm/tables.h
 create mode 100644 arch/unicore32/include/asm/ranges.h
 create mode 100644 arch/unicore32/include/asm/sections.h
 create mode 100644 arch/unicore32/include/asm/tables.h
 create mode 100644 arch/x86/include/asm/ranges.h
 create mode 100644 arch/x86/include/asm/tables.h
 create mode 100644 arch/xtensa/include/asm/ranges.h
 create mode 100644 arch/xtensa/include/asm/sections.h
 create mode 100644 arch/xtensa/include/asm/tables.h
 create mode 100644 include/asm-generic/ranges.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%)
 create mode 100644 tools/include/linux/sections.h

-- 
2.8.4


^ permalink raw reply	[flat|nested] 176+ messages in thread

* [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-07-22 21:24 ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe, Luis R. Rodriguez

This RFC v3 builds off the last RFC v2 series [0] for adding linker tables.
The largest amount of work here was to take Russell King's feedback on
using linker table for kprobes text not being appropriate -- and providing
another lightweight API for simple section ranges: read-only stitched pieces
of executable code. This required also generalizing common building blocks
for both linker tables and section ranges, these building blocks are defined
now in include/linux/sections.h and asm-generic/section.h. The other last thing
decided was to not support sub-sections. In the hunt for this I could think of
anything that really required this, and if it was needed it did not seem
impossible to port over to avoid its use. Please let me know if there are valid
uses cases for sub-sections.

Other significant effort here was to provide a set of common assembly helpers
which could be used across architectures, this starts off some of this work
for generic helpers which carve out and define custom Linux sections.

Lastly, this now also goes with two ports which required module support when
using linker tables: jump labels, and dynamic debug support. A few
extensions have been made to the original series in order to provide
support for that.

Since kprobes actually had both a linker table and a section range the
patch that dealt with kprobes is now split off in two patches, one
that deals with its linker table and another for its section ranges.

More elaborate uses for linker tables are possible, I'll hold off on any
of this type of work until at least the basic building blocks are fleshed
out. To review how this work came about, and more elaborate uses being
evaluated check out the userspace linker-tables mockup solution [1].
Hopefully most of the possible bikeshedding was already dealt with through
that tree. Thanks to hpa for tons of feedback.

Should you need it, the code here is also available on my linux-next
20160722-linker-table-v3-try2 branch on kernel.org [2]. Lastly, ranges and
table development go under copyleft-next, Rusty recently asked for code
to go in prior to the license tag being added denoting this license as
GPL-compatible [3] -- I had noted in the patch submission which annotated
copyleft-next's compatibility to GPLv2 that copyleft-next is the license
of choice for ongoing kernel development on my end [4]. If this is
objectionable I'm happy to change it to GPLv2 however I'd like a reason
provided as I've gone through all possible channels to ensure this is kosher,
including vetting by 3 attorneys now, 2 at SUSE.

This all goes tested by 0-day... however since I found an issue with linker
tables and blackfin this series remains as RFC -- I'll try to debug the
issue with Steven Miao. The issue with blackfin is using a config that
enables CONFIG_FW_LOADER=y and CONFIG_DYNAMIC_DEBUG=y [5] we end up with
the following at final link time:

  LD      init/built-in.o
lib/built-in.o: In function `dynamic_debug_init':
lib/dynamic_debug.c:(.init.text+0x156): undefined reference to `__verbose__end'
lib/dynamic_debug.c:(.init.text+0x15a): undefined reference to `__verbose__end'
lib/dynamic_debug.c:(.init.text+0x160): undefined reference to `__verbose'
lib/dynamic_debug.c:(.init.text+0x164): undefined reference to `__verbose'
lib/dynamic_debug.c:(.init.text+0x214): undefined reference to `__verbose__end'
lib/dynamic_debug.c:(.init.text+0x218): undefined reference to `__verbose__end'
lib/dynamic_debug.c:(.init.text+0x252): undefined reference to `__verbose__end'
lib/dynamic_debug.c:(.init.text+0x258): undefined reference to `__verbose'
lib/dynamic_debug.c:(.init.text+0x25c): undefined reference to `__verbose__end'
lib/dynamic_debug.c:(.init.text+0x260): undefined reference to `__verbose'
drivers/built-in.o: In function `release_firmware':
(.text+0x22dc2): undefined reference to `builtin_fw'
drivers/built-in.o: In function `release_firmware':
(.text+0x22dc6): undefined reference to `builtin_fw__end'
drivers/built-in.o: In function `release_firmware':
(.text+0x22dca): undefined reference to `builtin_fw'
drivers/built-in.o: In function `release_firmware':
(.text+0x22dce): undefined reference to `builtin_fw__end'
drivers/built-in.o: In function `fw_get_builtin_firmware':
drivers/base/firmware_class.c:(.text+0x23008): undefined reference to `builtin_fw'
drivers/base/firmware_class.c:(.text+0x2300c): undefined reference to `builtin_fw__end'
drivers/base/firmware_class.c:(.text+0x23010): undefined reference to `builtin_fw'
drivers/base/firmware_class.c:(.text+0x23014): undefined reference to `builtin_fw__end'
Makefile:957: recipe for target 'vmlinux' failed
make: *** [vmlinux] Error 1

To reproduce then:

wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
chmod +x ~/bin/make.cross
wget http://drvbp1.linux-foundation.org/~mcgrof/2016/07/22/blackfin-fw-dyndbg.config -o .config
make.cross ARCH=blackfin

[0] https://lkml.kernel.org/r/1455889559-9428-1-git-send-email-mcgrof@kernel.org
[1] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linker-tables.git/
[2] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linux-next.git/log/?h=20160722-linker-table-v3-try2
[3] https://lkml.kernel.org/r/87y44zhbiu.fsf@rustcorp.com.au
[4] https://lkml.kernel.org/r/1467327207-14916-1-git-send-email-mcgrof@kernel.org
[5] http://drvbp1.linux-foundation.org/~mcgrof/2016/07/22/blackfin-fw-dyndbg.config


Luis R. Rodriguez (13):
  x86: remove LTO_REFERENCE_INITCALL()
  dell-smo8800: include uaccess.h
  scripts/module-common.lds: enable generation
  sections.h: guard against asm and linker script
  sections.h: add sections header to collect all section info
  ranges.h: add helpers to build and identify Linux section ranges
  tables.h: add linker table support
  firmware/Makefile: force recompilation if makefile changes
  firmware: port built-in section to linker table
  jump_label: port __jump_table to linker tables
  dynamic_debug: port to use linker tables
  kprobes: port .kprobes.text to section range
  kprobes: port blacklist kprobes to linker table

 .gitignore                                         |   2 +
 Documentation/DocBook/Makefile                     |   3 +-
 Documentation/DocBook/linker-tables.tmpl           | 166 ++++++
 Documentation/DocBook/sections.tmpl                | 112 ++++
 Documentation/kbuild/makefiles.txt                 |  19 +
 Makefile                                           |   6 +-
 arch/alpha/include/asm/ranges.h                    |   6 +
 arch/alpha/include/asm/sections.h                  |   6 +
 arch/alpha/include/asm/tables.h                    |   6 +
 arch/arc/include/asm/ranges.h                      |   6 +
 arch/arc/include/asm/tables.h                      |   6 +
 arch/arc/kernel/vmlinux.lds.S                      |   1 -
 arch/arm/include/asm/jump_label.h                  |   6 +-
 arch/arm/include/asm/ranges.h                      |   6 +
 arch/arm/include/asm/sections.h                    |   2 +
 arch/arm/include/asm/tables.h                      |   6 +
 arch/arm/kernel/entry-armv.S                       |   3 +-
 arch/arm/kernel/vmlinux-xip.lds.S                  |   1 -
 arch/arm/kernel/vmlinux.lds.S                      |   1 -
 arch/arm64/include/asm/jump_label.h                |   6 +-
 arch/arm64/include/asm/ranges.h                    |   6 +
 arch/arm64/include/asm/sections.h                  |   6 +
 arch/arm64/include/asm/tables.h                    |   6 +
 arch/avr32/include/asm/ranges.h                    |   6 +
 arch/avr32/include/asm/sections.h                  |   6 +
 arch/avr32/include/asm/tables.h                    |   6 +
 arch/avr32/kernel/entry-avr32b.S                   |   5 +-
 arch/avr32/kernel/vmlinux.lds.S                    |   1 -
 arch/blackfin/include/asm/ranges.h                 |   6 +
 arch/blackfin/include/asm/sections.h               |   4 +
 arch/blackfin/include/asm/tables.h                 |   6 +
 arch/blackfin/kernel/vmlinux.lds.S                 |   1 -
 arch/c6x/include/asm/ranges.h                      |   6 +
 arch/c6x/include/asm/tables.h                      |   6 +
 arch/c6x/kernel/vmlinux.lds.S                      |   1 -
 arch/cris/include/asm/ranges.h                     |   6 +
 arch/cris/include/asm/sections.h                   |   6 +
 arch/cris/include/asm/tables.h                     |   6 +
 arch/frv/include/asm/ranges.h                      |   6 +
 arch/frv/include/asm/tables.h                      |   6 +
 arch/h8300/include/asm/ranges.h                    |   6 +
 arch/h8300/include/asm/sections.h                  |   6 +
 arch/h8300/include/asm/tables.h                    |   6 +
 arch/hexagon/include/asm/ranges.h                  |   6 +
 arch/hexagon/include/asm/sections.h                |   6 +
 arch/hexagon/include/asm/tables.h                  |   6 +
 arch/hexagon/kernel/vmlinux.lds.S                  |   1 -
 arch/ia64/include/asm/ranges.h                     |   6 +
 arch/ia64/include/asm/sections.h                   |   7 +-
 arch/ia64/include/asm/tables.h                     |   6 +
 arch/ia64/kernel/jprobes.S                         |   3 +-
 arch/ia64/kernel/vmlinux.lds.S                     |   1 -
 arch/ia64/lib/flush.S                              |   5 +-
 arch/m32r/include/asm/ranges.h                     |   6 +
 arch/m32r/include/asm/sections.h                   |   6 +
 arch/m32r/include/asm/tables.h                     |   6 +
 arch/m68k/include/asm/ranges.h                     |   6 +
 arch/m68k/include/asm/sections.h                   |   6 +
 arch/m68k/include/asm/tables.h                     |   6 +
 arch/metag/include/asm/ranges.h                    |   6 +
 arch/metag/include/asm/sections.h                  |   6 +
 arch/metag/include/asm/tables.h                    |   6 +
 arch/metag/kernel/vmlinux.lds.S                    |   1 -
 arch/microblaze/include/asm/ranges.h               |   6 +
 arch/microblaze/include/asm/tables.h               |   6 +
 arch/microblaze/kernel/vmlinux.lds.S               |   1 -
 arch/mips/include/asm/jump_label.h                 |   6 +-
 arch/mips/include/asm/ranges.h                     |   6 +
 arch/mips/include/asm/sections.h                   |   6 +
 arch/mips/include/asm/tables.h                     |   6 +
 arch/mips/kernel/vmlinux.lds.S                     |   1 -
 arch/mn10300/include/asm/ranges.h                  |   6 +
 arch/mn10300/include/asm/sections.h                |   6 +
 arch/mn10300/include/asm/tables.h                  |   6 +
 arch/mn10300/kernel/vmlinux.lds.S                  |   1 -
 arch/nios2/include/asm/ranges.h                    |   6 +
 arch/nios2/include/asm/sections.h                  |   6 +
 arch/nios2/include/asm/tables.h                    |   6 +
 arch/nios2/kernel/vmlinux.lds.S                    |   1 -
 arch/openrisc/include/asm/ranges.h                 |   6 +
 arch/openrisc/include/asm/sections.h               |   6 +
 arch/openrisc/include/asm/tables.h                 |   6 +
 arch/openrisc/kernel/vmlinux.lds.S                 |   1 -
 arch/parisc/include/asm/ranges.h                   |   6 +
 arch/parisc/include/asm/tables.h                   |   6 +
 arch/parisc/kernel/vmlinux.lds.S                   |   1 -
 arch/powerpc/include/asm/jump_label.h              |   8 +-
 arch/powerpc/include/asm/ppc_asm.h                 |   7 +-
 arch/powerpc/include/asm/ranges.h                  |   6 +
 arch/powerpc/include/asm/sections.h                |  11 +-
 arch/powerpc/include/asm/tables.h                  |   6 +
 arch/powerpc/kernel/vmlinux.lds.S                  |   1 -
 arch/s390/include/asm/jump_label.h                 |   6 +-
 arch/s390/include/asm/ranges.h                     |   6 +
 arch/s390/include/asm/tables.h                     |   6 +
 arch/s390/kernel/entry.S                           |   5 +-
 arch/s390/kernel/kprobes.c                         |   6 +-
 arch/s390/kernel/mcount.S                          |   2 +-
 arch/s390/kernel/vmlinux.lds.S                     |   1 -
 arch/score/include/asm/ranges.h                    |   6 +
 arch/score/include/asm/sections.h                  |   6 +
 arch/score/include/asm/tables.h                    |   6 +
 arch/score/kernel/vmlinux.lds.S                    |   1 -
 arch/sh/include/asm/ranges.h                       |   6 +
 arch/sh/include/asm/sections.h                     |   2 +
 arch/sh/include/asm/tables.h                       |   6 +
 arch/sh/kernel/vmlinux.lds.S                       |   1 -
 arch/sparc/include/asm/jump_label.h                |   6 +-
 arch/sparc/include/asm/ranges.h                    |   6 +
 arch/sparc/include/asm/sections.h                  |   4 +
 arch/sparc/include/asm/tables.h                    |   6 +
 arch/sparc/kernel/vmlinux.lds.S                    |   1 -
 arch/sparc/mm/ultra.S                              |   3 +-
 arch/tile/include/asm/ranges.h                     |   6 +
 arch/tile/include/asm/sections.h                   |   4 +
 arch/tile/include/asm/tables.h                     |   6 +
 arch/tile/kernel/vmlinux.lds.S                     |   1 -
 arch/um/include/asm/ranges.h                       |   6 +
 arch/um/include/asm/tables.h                       |   6 +
 arch/unicore32/include/asm/ranges.h                |   6 +
 arch/unicore32/include/asm/sections.h              |   6 +
 arch/unicore32/include/asm/tables.h                |   6 +
 arch/x86/include/asm/jump_label.h                  |  10 +-
 arch/x86/include/asm/ranges.h                      |   6 +
 arch/x86/include/asm/sections.h                    |  23 +-
 arch/x86/include/asm/tables.h                      |   6 +
 arch/x86/include/asm/uaccess.h                     |  18 +-
 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                            |   3 +
 arch/xtensa/include/asm/ranges.h                   |   6 +
 arch/xtensa/include/asm/sections.h                 |   6 +
 arch/xtensa/include/asm/tables.h                   |   6 +
 drivers/base/firmware_class.c                      |  12 +-
 drivers/platform/x86/dell-smo8800.c                |   1 +
 firmware/Makefile                                  |   7 +-
 include/asm-generic/ranges.h                       |  70 +++
 include/asm-generic/sections.h                     | 306 ++++++++++-
 include/asm-generic/tables.h                       |  70 +++
 include/asm-generic/vmlinux.lds.h                  |  66 +--
 include/linux/compiler.h                           |   2 +-
 include/linux/dynamic_debug.h                      |   5 +-
 include/linux/init.h                               |  20 +-
 include/linux/jump_label.h                         |  10 +-
 include/linux/kprobes.h                            |   8 +-
 include/linux/ranges.h                             |  54 ++
 include/linux/sections.h                           | 123 +++++
 include/linux/tables.h                             | 597 +++++++++++++++++++++
 kernel/jump_label.c                                |  17 +-
 kernel/kprobes.c                                   |  17 +-
 lib/dynamic_debug.c                                |  13 +-
 scripts/Makefile                                   |   1 +
 scripts/Makefile.build                             |   4 +-
 scripts/Makefile.clean                             |   1 +
 scripts/Makefile.lib                               |  12 +
 scripts/Makefile.modpost                           |   2 +-
 scripts/mod/Makefile                               |   2 +
 scripts/mod/modpost.c                              |   8 +-
 scripts/{module-common.lds => module-common.lds.S} |   6 +
 scripts/recordmcount.c                             |   7 +-
 scripts/recordmcount.pl                            |   2 +-
 tools/include/linux/sections.h                     |  13 +
 tools/objtool/special.c                            |   8 +-
 164 files changed, 2241 insertions(+), 205 deletions(-)
 create mode 100644 Documentation/DocBook/linker-tables.tmpl
 create mode 100644 Documentation/DocBook/sections.tmpl
 create mode 100644 arch/alpha/include/asm/ranges.h
 create mode 100644 arch/alpha/include/asm/sections.h
 create mode 100644 arch/alpha/include/asm/tables.h
 create mode 100644 arch/arc/include/asm/ranges.h
 create mode 100644 arch/arc/include/asm/tables.h
 create mode 100644 arch/arm/include/asm/ranges.h
 create mode 100644 arch/arm/include/asm/tables.h
 create mode 100644 arch/arm64/include/asm/ranges.h
 create mode 100644 arch/arm64/include/asm/sections.h
 create mode 100644 arch/arm64/include/asm/tables.h
 create mode 100644 arch/avr32/include/asm/ranges.h
 create mode 100644 arch/avr32/include/asm/sections.h
 create mode 100644 arch/avr32/include/asm/tables.h
 create mode 100644 arch/blackfin/include/asm/ranges.h
 create mode 100644 arch/blackfin/include/asm/tables.h
 create mode 100644 arch/c6x/include/asm/ranges.h
 create mode 100644 arch/c6x/include/asm/tables.h
 create mode 100644 arch/cris/include/asm/ranges.h
 create mode 100644 arch/cris/include/asm/sections.h
 create mode 100644 arch/cris/include/asm/tables.h
 create mode 100644 arch/frv/include/asm/ranges.h
 create mode 100644 arch/frv/include/asm/tables.h
 create mode 100644 arch/h8300/include/asm/ranges.h
 create mode 100644 arch/h8300/include/asm/sections.h
 create mode 100644 arch/h8300/include/asm/tables.h
 create mode 100644 arch/hexagon/include/asm/ranges.h
 create mode 100644 arch/hexagon/include/asm/sections.h
 create mode 100644 arch/hexagon/include/asm/tables.h
 create mode 100644 arch/ia64/include/asm/ranges.h
 create mode 100644 arch/ia64/include/asm/tables.h
 create mode 100644 arch/m32r/include/asm/ranges.h
 create mode 100644 arch/m32r/include/asm/sections.h
 create mode 100644 arch/m32r/include/asm/tables.h
 create mode 100644 arch/m68k/include/asm/ranges.h
 create mode 100644 arch/m68k/include/asm/sections.h
 create mode 100644 arch/m68k/include/asm/tables.h
 create mode 100644 arch/metag/include/asm/ranges.h
 create mode 100644 arch/metag/include/asm/sections.h
 create mode 100644 arch/metag/include/asm/tables.h
 create mode 100644 arch/microblaze/include/asm/ranges.h
 create mode 100644 arch/microblaze/include/asm/tables.h
 create mode 100644 arch/mips/include/asm/ranges.h
 create mode 100644 arch/mips/include/asm/sections.h
 create mode 100644 arch/mips/include/asm/tables.h
 create mode 100644 arch/mn10300/include/asm/ranges.h
 create mode 100644 arch/mn10300/include/asm/sections.h
 create mode 100644 arch/mn10300/include/asm/tables.h
 create mode 100644 arch/nios2/include/asm/ranges.h
 create mode 100644 arch/nios2/include/asm/sections.h
 create mode 100644 arch/nios2/include/asm/tables.h
 create mode 100644 arch/openrisc/include/asm/ranges.h
 create mode 100644 arch/openrisc/include/asm/sections.h
 create mode 100644 arch/openrisc/include/asm/tables.h
 create mode 100644 arch/parisc/include/asm/ranges.h
 create mode 100644 arch/parisc/include/asm/tables.h
 create mode 100644 arch/powerpc/include/asm/ranges.h
 create mode 100644 arch/powerpc/include/asm/tables.h
 create mode 100644 arch/s390/include/asm/ranges.h
 create mode 100644 arch/s390/include/asm/tables.h
 create mode 100644 arch/score/include/asm/ranges.h
 create mode 100644 arch/score/include/asm/sections.h
 create mode 100644 arch/score/include/asm/tables.h
 create mode 100644 arch/sh/include/asm/ranges.h
 create mode 100644 arch/sh/include/asm/tables.h
 create mode 100644 arch/sparc/include/asm/ranges.h
 create mode 100644 arch/sparc/include/asm/tables.h
 create mode 100644 arch/tile/include/asm/ranges.h
 create mode 100644 arch/tile/include/asm/tables.h
 create mode 100644 arch/um/include/asm/ranges.h
 create mode 100644 arch/um/include/asm/tables.h
 create mode 100644 arch/unicore32/include/asm/ranges.h
 create mode 100644 arch/unicore32/include/asm/sections.h
 create mode 100644 arch/unicore32/include/asm/tables.h
 create mode 100644 arch/x86/include/asm/ranges.h
 create mode 100644 arch/x86/include/asm/tables.h
 create mode 100644 arch/xtensa/include/asm/ranges.h
 create mode 100644 arch/xtensa/include/asm/sections.h
 create mode 100644 arch/xtensa/include/asm/tables.h
 create mode 100644 include/asm-generic/ranges.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%)
 create mode 100644 tools/include/linux/sections.h

-- 
2.8.4


^ permalink raw reply	[flat|nested] 176+ messages in thread

* [RFC v3 01/13] x86: remove LTO_REFERENCE_INITCALL()
  2016-07-22 21:24 ` Luis R. Rodriguez
  (?)
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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.

Acked-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 include/linux/init.h | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/include/linux/init.h b/include/linux/init.h
index 1e5c131d5c9a..aa662ad80d9c 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -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.
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 01/13] x86: remove LTO_REFERENCE_INITCALL()
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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.

Acked-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 include/linux/init.h | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/include/linux/init.h b/include/linux/init.h
index 1e5c131d5c9a..aa662ad80d9c 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -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.
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 01/13] x86: remove LTO_REFERENCE_INITCALL()
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe, Luis R. Rodriguez

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.

Acked-by: Andi Kleen <ak@linux.intel.com>
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 include/linux/init.h | 20 +-------------------
 1 file changed, 1 insertion(+), 19 deletions(-)

diff --git a/include/linux/init.h b/include/linux/init.h
index 1e5c131d5c9a..aa662ad80d9c 100644
--- a/include/linux/init.h
+++ b/include/linux/init.h
@@ -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.
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 02/13] dell-smo8800: include uaccess.h
  2016-07-22 21:24 ` Luis R. Rodriguez
  (?)
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 drivers/platform/x86/dell-smo8800.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/platform/x86/dell-smo8800.c b/drivers/platform/x86/dell-smo8800.c
index 0aec4fd4c48e..37e646034ef8 100644
--- a/drivers/platform/x86/dell-smo8800.c
+++ b/drivers/platform/x86/dell-smo8800.c
@@ -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 */
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 02/13] dell-smo8800: include uaccess.h
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 drivers/platform/x86/dell-smo8800.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/platform/x86/dell-smo8800.c b/drivers/platform/x86/dell-smo8800.c
index 0aec4fd4c48e..37e646034ef8 100644
--- a/drivers/platform/x86/dell-smo8800.c
+++ b/drivers/platform/x86/dell-smo8800.c
@@ -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 */
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 02/13] dell-smo8800: include uaccess.h
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe, Luis R. Rodriguez

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 drivers/platform/x86/dell-smo8800.c | 1 +
 1 file changed, 1 insertion(+)

diff --git a/drivers/platform/x86/dell-smo8800.c b/drivers/platform/x86/dell-smo8800.c
index 0aec4fd4c48e..37e646034ef8 100644
--- a/drivers/platform/x86/dell-smo8800.c
+++ b/drivers/platform/x86/dell-smo8800.c
@@ -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 */
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 03/13] scripts/module-common.lds: enable generation
  2016-07-22 21:24 ` Luis R. Rodriguez
  (?)
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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.

v3: new to this series

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 .gitignore                                         | 2 ++
 Makefile                                           | 6 +++++-
 scripts/Makefile.modpost                           | 2 +-
 scripts/{module-common.lds => module-common.lds.S} | 0
 4 files changed, 8 insertions(+), 2 deletions(-)
 rename scripts/{module-common.lds => module-common.lds.S} (100%)

diff --git a/.gitignore b/.gitignore
index 2be25f771bd8..14a94d939a6f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -113,3 +113,5 @@ all.config
 
 # Kdevelop4
 *.kdev4
+
+scripts/module-common.lds
diff --git a/Makefile b/Makefile
index caa33e007a8c..c56cca906769 100644
--- a/Makefile
+++ b/Makefile
@@ -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)
@@ -1178,7 +1182,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
diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index 1366a94b6c39..2d8aff7735d6 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -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)
diff --git a/scripts/module-common.lds b/scripts/module-common.lds.S
similarity index 100%
rename from scripts/module-common.lds
rename to scripts/module-common.lds.S
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 03/13] scripts/module-common.lds: enable generation
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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.

v3: new to this series

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 .gitignore                                         | 2 ++
 Makefile                                           | 6 +++++-
 scripts/Makefile.modpost                           | 2 +-
 scripts/{module-common.lds => module-common.lds.S} | 0
 4 files changed, 8 insertions(+), 2 deletions(-)
 rename scripts/{module-common.lds => module-common.lds.S} (100%)

diff --git a/.gitignore b/.gitignore
index 2be25f771bd8..14a94d939a6f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -113,3 +113,5 @@ all.config
 
 # Kdevelop4
 *.kdev4
+
+scripts/module-common.lds
diff --git a/Makefile b/Makefile
index caa33e007a8c..c56cca906769 100644
--- a/Makefile
+++ b/Makefile
@@ -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)
@@ -1178,7 +1182,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
diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index 1366a94b6c39..2d8aff7735d6 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -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)
diff --git a/scripts/module-common.lds b/scripts/module-common.lds.S
similarity index 100%
rename from scripts/module-common.lds
rename to scripts/module-common.lds.S
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 03/13] scripts/module-common.lds: enable generation
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe, Luis R. Rodriguez

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.

v3: new to this series

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 .gitignore                                         | 2 ++
 Makefile                                           | 6 +++++-
 scripts/Makefile.modpost                           | 2 +-
 scripts/{module-common.lds => module-common.lds.S} | 0
 4 files changed, 8 insertions(+), 2 deletions(-)
 rename scripts/{module-common.lds => module-common.lds.S} (100%)

diff --git a/.gitignore b/.gitignore
index 2be25f771bd8..14a94d939a6f 100644
--- a/.gitignore
+++ b/.gitignore
@@ -113,3 +113,5 @@ all.config
 
 # Kdevelop4
 *.kdev4
+
+scripts/module-common.lds
diff --git a/Makefile b/Makefile
index caa33e007a8c..c56cca906769 100644
--- a/Makefile
+++ b/Makefile
@@ -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)
@@ -1178,7 +1182,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
diff --git a/scripts/Makefile.modpost b/scripts/Makefile.modpost
index 1366a94b6c39..2d8aff7735d6 100644
--- a/scripts/Makefile.modpost
+++ b/scripts/Makefile.modpost
@@ -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)
diff --git a/scripts/module-common.lds b/scripts/module-common.lds.S
similarity index 100%
rename from scripts/module-common.lds
rename to scripts/module-common.lds.S
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 04/13] sections.h: guard against asm and linker script
  2016-07-22 21:24 ` Luis R. Rodriguez
  (?)
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

We'll later add some generic helpers for use in the linker scripts
and some generic asm code for all architectures. To do that we'll
first need to guard against linker script and asm code.

On x86 uaccess.h has a struct which is used as part of a section,
move that to sections.h as we otherwise have no need for uaccess.h
on sections.h

v3: new to this series, needed due to the collateral of the split of
    tables.h into 3 files: tables.h, ranges.h and sections.h, the
    need to guard sections.h is due to the fact that sections.h is
    already included and expanded considerably in certain architectures.

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 arch/arm/include/asm/sections.h      |  2 ++
 arch/blackfin/include/asm/sections.h |  4 ++++
 arch/ia64/include/asm/sections.h     |  7 +++++--
 arch/powerpc/include/asm/sections.h  | 11 ++++++-----
 arch/sh/include/asm/sections.h       |  2 ++
 arch/sparc/include/asm/sections.h    |  4 ++++
 arch/tile/include/asm/sections.h     |  4 ++++
 arch/x86/include/asm/sections.h      | 23 ++++++++++++++++++++++-
 arch/x86/include/asm/uaccess.h       | 18 +-----------------
 include/asm-generic/sections.h       |  4 ++++
 10 files changed, 54 insertions(+), 25 deletions(-)

diff --git a/arch/arm/include/asm/sections.h b/arch/arm/include/asm/sections.h
index 803bbf2b20b8..21830b9b3b6b 100644
--- a/arch/arm/include/asm/sections.h
+++ b/arch/arm/include/asm/sections.h
@@ -3,6 +3,8 @@
 
 #include <asm-generic/sections.h>
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
 extern char _exiprom[];
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
 
 #endif	/* _ASM_ARM_SECTIONS_H */
diff --git a/arch/blackfin/include/asm/sections.h b/arch/blackfin/include/asm/sections.h
index fbd408475725..d2abd7a585dd 100644
--- a/arch/blackfin/include/asm/sections.h
+++ b/arch/blackfin/include/asm/sections.h
@@ -7,6 +7,8 @@
 #ifndef _BLACKFIN_SECTIONS_H
 #define _BLACKFIN_SECTIONS_H
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
+
 /* only used when MTD_UCLINUX */
 extern unsigned long memory_mtd_start, memory_mtd_end, mtd_size;
 
@@ -62,6 +64,8 @@ static inline int arch_is_kernel_data(unsigned long addr)
 }
 #define arch_is_kernel_data(addr) arch_is_kernel_data(addr)
 
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
+
 #include <asm-generic/sections.h>
 
 #endif
diff --git a/arch/ia64/include/asm/sections.h b/arch/ia64/include/asm/sections.h
index 2ab2003698ef..3318e3916122 100644
--- a/arch/ia64/include/asm/sections.h
+++ b/arch/ia64/include/asm/sections.h
@@ -6,9 +6,12 @@
  *	David Mosberger-Tang <davidm@hpl.hp.com>
  */
 
+#include <asm-generic/sections.h>
+
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
+
 #include <linux/elf.h>
 #include <linux/uaccess.h>
-#include <asm-generic/sections.h>
 
 extern char __phys_per_cpu_start[];
 #ifdef	CONFIG_SMP
@@ -37,6 +40,6 @@ static inline void *dereference_function_descriptor(void *ptr)
 	return ptr;
 }
 
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
 
 #endif /* _ASM_IA64_SECTIONS_H */
-
diff --git a/arch/powerpc/include/asm/sections.h b/arch/powerpc/include/asm/sections.h
index 7dc006b58369..f226b5bcd27c 100644
--- a/arch/powerpc/include/asm/sections.h
+++ b/arch/powerpc/include/asm/sections.h
@@ -1,11 +1,12 @@
 #ifndef _ASM_POWERPC_SECTIONS_H
 #define _ASM_POWERPC_SECTIONS_H
-#ifdef __KERNEL__
 
-#include <linux/elf.h>
-#include <linux/uaccess.h>
 #include <asm-generic/sections.h>
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
+
+#include <linux/elf.h>
+#include <linux/uaccess.h>
 #ifdef __powerpc64__
 
 extern char __start_interrupts[];
@@ -75,7 +76,7 @@ static inline void *dereference_function_descriptor(void *ptr)
 }
 #endif /* PPC64_ELF_ABI_v1 */
 
-#endif
+#endif /* __powerpc64__ */
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
 
-#endif /* __KERNEL__ */
 #endif	/* _ASM_POWERPC_SECTIONS_H */
diff --git a/arch/sh/include/asm/sections.h b/arch/sh/include/asm/sections.h
index 7a99e6af6372..ad4f9cbd861d 100644
--- a/arch/sh/include/asm/sections.h
+++ b/arch/sh/include/asm/sections.h
@@ -3,9 +3,11 @@
 
 #include <asm-generic/sections.h>
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
 extern long __machvec_start, __machvec_end;
 extern char __uncached_start, __uncached_end;
 extern char __start_eh_frame[], __stop_eh_frame[];
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
 
 #endif /* __ASM_SH_SECTIONS_H */
 
diff --git a/arch/sparc/include/asm/sections.h b/arch/sparc/include/asm/sections.h
index f300d1a9b2b6..b07a2380863e 100644
--- a/arch/sparc/include/asm/sections.h
+++ b/arch/sparc/include/asm/sections.h
@@ -4,10 +4,14 @@
 /* nothing to see, move along */
 #include <asm-generic/sections.h>
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
+
 /* sparc entry point */
 extern char _start[];
 
 extern char __leon_1insn_patch[];
 extern char __leon_1insn_patch_end[];
 
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
+
 #endif
diff --git a/arch/tile/include/asm/sections.h b/arch/tile/include/asm/sections.h
index 86a746243dc8..f9cce7c6d8ba 100644
--- a/arch/tile/include/asm/sections.h
+++ b/arch/tile/include/asm/sections.h
@@ -19,6 +19,8 @@
 
 #include <asm-generic/sections.h>
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
+
 /* Write-once data is writable only till the end of initialization. */
 extern char __w1data_begin[], __w1data_end[];
 
@@ -44,4 +46,6 @@ static inline int arch_is_kernel_data(unsigned long addr)
 		addr < (unsigned long)_end;
 }
 
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
+
 #endif /* _ASM_TILE_SECTIONS_H */
diff --git a/arch/x86/include/asm/sections.h b/arch/x86/include/asm/sections.h
index 13b6cdd0af57..84c7044c82bf 100644
--- a/arch/x86/include/asm/sections.h
+++ b/arch/x86/include/asm/sections.h
@@ -2,13 +2,34 @@
 #define _ASM_X86_SECTIONS_H
 
 #include <asm-generic/sections.h>
-#include <asm/uaccess.h>
+
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
 
 extern char __brk_base[], __brk_limit[];
+
+/*
+ * The exception table consists of triples of addresses relative to the
+ * exception table entry itself. The first address is of an instruction
+ * that is allowed to fault, the second is the target at which the program
+ * should continue. The third is a handler function to deal with the fault
+ * caused by the instruction in the first field.
+ *
+ * All the routines below use bits of fixup code that are out of line
+ * with the main instruction path.  This means when everything is well,
+ * we don't even have to jump over them.  Further, they do not intrude
+ * on our cache or tlb entries.
+ */
+
+struct exception_table_entry {
+	int insn, fixup, handler;
+};
+
 extern struct exception_table_entry __stop___ex_table[];
 
 #if defined(CONFIG_X86_64)
 extern char __end_rodata_hpage_align[];
 #endif
 
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
+
 #endif	/* _ASM_X86_SECTIONS_H */
diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index a2f253c091e3..d661f28e4e00 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -8,6 +8,7 @@
 #include <linux/kasan-checks.h>
 #include <linux/thread_info.h>
 #include <linux/string.h>
+#include <asm/sections.h>
 #include <asm/asm.h>
 #include <asm/page.h>
 #include <asm/smap.h>
@@ -90,23 +91,6 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
 #define access_ok(type, addr, size) \
 	likely(!__range_not_ok(addr, size, user_addr_max()))
 
-/*
- * The exception table consists of triples of addresses relative to the
- * exception table entry itself. The first address is of an instruction
- * that is allowed to fault, the second is the target at which the program
- * should continue. The third is a handler function to deal with the fault
- * caused by the instruction in the first field.
- *
- * All the routines below use bits of fixup code that are out of line
- * with the main instruction path.  This means when everything is well,
- * we don't even have to jump over them.  Further, they do not intrude
- * on our cache or tlb entries.
- */
-
-struct exception_table_entry {
-	int insn, fixup, handler;
-};
-
 #define ARCH_HAS_RELATIVE_EXTABLE
 
 #define swap_ex_entry_fixup(a, b, tmp, delta)			\
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index af0254c09424..efd51e70a8db 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -1,6 +1,8 @@
 #ifndef _ASM_GENERIC_SECTIONS_H_
 #define _ASM_GENERIC_SECTIONS_H_
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
+
 /* References to section boundaries */
 
 #include <linux/compiler.h>
@@ -128,4 +130,6 @@ static inline bool init_section_intersects(void *virt, size_t size)
 	return memory_intersects(__init_begin, __init_end, virt, size);
 }
 
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
+
 #endif /* _ASM_GENERIC_SECTIONS_H_ */
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 04/13] sections.h: guard against asm and linker script
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

We'll later add some generic helpers for use in the linker scripts
and some generic asm code for all architectures. To do that we'll
first need to guard against linker script and asm code.

On x86 uaccess.h has a struct which is used as part of a section,
move that to sections.h as we otherwise have no need for uaccess.h
on sections.h

v3: new to this series, needed due to the collateral of the split of
    tables.h into 3 files: tables.h, ranges.h and sections.h, the
    need to guard sections.h is due to the fact that sections.h is
    already included and expanded considerably in certain architectures.

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 arch/arm/include/asm/sections.h      |  2 ++
 arch/blackfin/include/asm/sections.h |  4 ++++
 arch/ia64/include/asm/sections.h     |  7 +++++--
 arch/powerpc/include/asm/sections.h  | 11 ++++++-----
 arch/sh/include/asm/sections.h       |  2 ++
 arch/sparc/include/asm/sections.h    |  4 ++++
 arch/tile/include/asm/sections.h     |  4 ++++
 arch/x86/include/asm/sections.h      | 23 ++++++++++++++++++++++-
 arch/x86/include/asm/uaccess.h       | 18 +-----------------
 include/asm-generic/sections.h       |  4 ++++
 10 files changed, 54 insertions(+), 25 deletions(-)

diff --git a/arch/arm/include/asm/sections.h b/arch/arm/include/asm/sections.h
index 803bbf2b20b8..21830b9b3b6b 100644
--- a/arch/arm/include/asm/sections.h
+++ b/arch/arm/include/asm/sections.h
@@ -3,6 +3,8 @@
 
 #include <asm-generic/sections.h>
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
 extern char _exiprom[];
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
 
 #endif	/* _ASM_ARM_SECTIONS_H */
diff --git a/arch/blackfin/include/asm/sections.h b/arch/blackfin/include/asm/sections.h
index fbd408475725..d2abd7a585dd 100644
--- a/arch/blackfin/include/asm/sections.h
+++ b/arch/blackfin/include/asm/sections.h
@@ -7,6 +7,8 @@
 #ifndef _BLACKFIN_SECTIONS_H
 #define _BLACKFIN_SECTIONS_H
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
+
 /* only used when MTD_UCLINUX */
 extern unsigned long memory_mtd_start, memory_mtd_end, mtd_size;
 
@@ -62,6 +64,8 @@ static inline int arch_is_kernel_data(unsigned long addr)
 }
 #define arch_is_kernel_data(addr) arch_is_kernel_data(addr)
 
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
+
 #include <asm-generic/sections.h>
 
 #endif
diff --git a/arch/ia64/include/asm/sections.h b/arch/ia64/include/asm/sections.h
index 2ab2003698ef..3318e3916122 100644
--- a/arch/ia64/include/asm/sections.h
+++ b/arch/ia64/include/asm/sections.h
@@ -6,9 +6,12 @@
  *	David Mosberger-Tang <davidm@hpl.hp.com>
  */
 
+#include <asm-generic/sections.h>
+
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
+
 #include <linux/elf.h>
 #include <linux/uaccess.h>
-#include <asm-generic/sections.h>
 
 extern char __phys_per_cpu_start[];
 #ifdef	CONFIG_SMP
@@ -37,6 +40,6 @@ static inline void *dereference_function_descriptor(void *ptr)
 	return ptr;
 }
 
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
 
 #endif /* _ASM_IA64_SECTIONS_H */
-
diff --git a/arch/powerpc/include/asm/sections.h b/arch/powerpc/include/asm/sections.h
index 7dc006b58369..f226b5bcd27c 100644
--- a/arch/powerpc/include/asm/sections.h
+++ b/arch/powerpc/include/asm/sections.h
@@ -1,11 +1,12 @@
 #ifndef _ASM_POWERPC_SECTIONS_H
 #define _ASM_POWERPC_SECTIONS_H
-#ifdef __KERNEL__
 
-#include <linux/elf.h>
-#include <linux/uaccess.h>
 #include <asm-generic/sections.h>
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
+
+#include <linux/elf.h>
+#include <linux/uaccess.h>
 #ifdef __powerpc64__
 
 extern char __start_interrupts[];
@@ -75,7 +76,7 @@ static inline void *dereference_function_descriptor(void *ptr)
 }
 #endif /* PPC64_ELF_ABI_v1 */
 
-#endif
+#endif /* __powerpc64__ */
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
 
-#endif /* __KERNEL__ */
 #endif	/* _ASM_POWERPC_SECTIONS_H */
diff --git a/arch/sh/include/asm/sections.h b/arch/sh/include/asm/sections.h
index 7a99e6af6372..ad4f9cbd861d 100644
--- a/arch/sh/include/asm/sections.h
+++ b/arch/sh/include/asm/sections.h
@@ -3,9 +3,11 @@
 
 #include <asm-generic/sections.h>
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
 extern long __machvec_start, __machvec_end;
 extern char __uncached_start, __uncached_end;
 extern char __start_eh_frame[], __stop_eh_frame[];
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
 
 #endif /* __ASM_SH_SECTIONS_H */
 
diff --git a/arch/sparc/include/asm/sections.h b/arch/sparc/include/asm/sections.h
index f300d1a9b2b6..b07a2380863e 100644
--- a/arch/sparc/include/asm/sections.h
+++ b/arch/sparc/include/asm/sections.h
@@ -4,10 +4,14 @@
 /* nothing to see, move along */
 #include <asm-generic/sections.h>
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
+
 /* sparc entry point */
 extern char _start[];
 
 extern char __leon_1insn_patch[];
 extern char __leon_1insn_patch_end[];
 
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
+
 #endif
diff --git a/arch/tile/include/asm/sections.h b/arch/tile/include/asm/sections.h
index 86a746243dc8..f9cce7c6d8ba 100644
--- a/arch/tile/include/asm/sections.h
+++ b/arch/tile/include/asm/sections.h
@@ -19,6 +19,8 @@
 
 #include <asm-generic/sections.h>
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
+
 /* Write-once data is writable only till the end of initialization. */
 extern char __w1data_begin[], __w1data_end[];
 
@@ -44,4 +46,6 @@ static inline int arch_is_kernel_data(unsigned long addr)
 		addr < (unsigned long)_end;
 }
 
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
+
 #endif /* _ASM_TILE_SECTIONS_H */
diff --git a/arch/x86/include/asm/sections.h b/arch/x86/include/asm/sections.h
index 13b6cdd0af57..84c7044c82bf 100644
--- a/arch/x86/include/asm/sections.h
+++ b/arch/x86/include/asm/sections.h
@@ -2,13 +2,34 @@
 #define _ASM_X86_SECTIONS_H
 
 #include <asm-generic/sections.h>
-#include <asm/uaccess.h>
+
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
 
 extern char __brk_base[], __brk_limit[];
+
+/*
+ * The exception table consists of triples of addresses relative to the
+ * exception table entry itself. The first address is of an instruction
+ * that is allowed to fault, the second is the target at which the program
+ * should continue. The third is a handler function to deal with the fault
+ * caused by the instruction in the first field.
+ *
+ * All the routines below use bits of fixup code that are out of line
+ * with the main instruction path.  This means when everything is well,
+ * we don't even have to jump over them.  Further, they do not intrude
+ * on our cache or tlb entries.
+ */
+
+struct exception_table_entry {
+	int insn, fixup, handler;
+};
+
 extern struct exception_table_entry __stop___ex_table[];
 
 #if defined(CONFIG_X86_64)
 extern char __end_rodata_hpage_align[];
 #endif
 
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
+
 #endif	/* _ASM_X86_SECTIONS_H */
diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index a2f253c091e3..d661f28e4e00 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -8,6 +8,7 @@
 #include <linux/kasan-checks.h>
 #include <linux/thread_info.h>
 #include <linux/string.h>
+#include <asm/sections.h>
 #include <asm/asm.h>
 #include <asm/page.h>
 #include <asm/smap.h>
@@ -90,23 +91,6 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
 #define access_ok(type, addr, size) \
 	likely(!__range_not_ok(addr, size, user_addr_max()))
 
-/*
- * The exception table consists of triples of addresses relative to the
- * exception table entry itself. The first address is of an instruction
- * that is allowed to fault, the second is the target at which the program
- * should continue. The third is a handler function to deal with the fault
- * caused by the instruction in the first field.
- *
- * All the routines below use bits of fixup code that are out of line
- * with the main instruction path.  This means when everything is well,
- * we don't even have to jump over them.  Further, they do not intrude
- * on our cache or tlb entries.
- */
-
-struct exception_table_entry {
-	int insn, fixup, handler;
-};
-
 #define ARCH_HAS_RELATIVE_EXTABLE
 
 #define swap_ex_entry_fixup(a, b, tmp, delta)			\
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index af0254c09424..efd51e70a8db 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -1,6 +1,8 @@
 #ifndef _ASM_GENERIC_SECTIONS_H_
 #define _ASM_GENERIC_SECTIONS_H_
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
+
 /* References to section boundaries */
 
 #include <linux/compiler.h>
@@ -128,4 +130,6 @@ static inline bool init_section_intersects(void *virt, size_t size)
 	return memory_intersects(__init_begin, __init_end, virt, size);
 }
 
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
+
 #endif /* _ASM_GENERIC_SECTIONS_H_ */
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 04/13] sections.h: guard against asm and linker script
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe, Luis R. Rodriguez

We'll later add some generic helpers for use in the linker scripts
and some generic asm code for all architectures. To do that we'll
first need to guard against linker script and asm code.

On x86 uaccess.h has a struct which is used as part of a section,
move that to sections.h as we otherwise have no need for uaccess.h
on sections.h

v3: new to this series, needed due to the collateral of the split of
    tables.h into 3 files: tables.h, ranges.h and sections.h, the
    need to guard sections.h is due to the fact that sections.h is
    already included and expanded considerably in certain architectures.

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 arch/arm/include/asm/sections.h      |  2 ++
 arch/blackfin/include/asm/sections.h |  4 ++++
 arch/ia64/include/asm/sections.h     |  7 +++++--
 arch/powerpc/include/asm/sections.h  | 11 ++++++-----
 arch/sh/include/asm/sections.h       |  2 ++
 arch/sparc/include/asm/sections.h    |  4 ++++
 arch/tile/include/asm/sections.h     |  4 ++++
 arch/x86/include/asm/sections.h      | 23 ++++++++++++++++++++++-
 arch/x86/include/asm/uaccess.h       | 18 +-----------------
 include/asm-generic/sections.h       |  4 ++++
 10 files changed, 54 insertions(+), 25 deletions(-)

diff --git a/arch/arm/include/asm/sections.h b/arch/arm/include/asm/sections.h
index 803bbf2b20b8..21830b9b3b6b 100644
--- a/arch/arm/include/asm/sections.h
+++ b/arch/arm/include/asm/sections.h
@@ -3,6 +3,8 @@
 
 #include <asm-generic/sections.h>
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
 extern char _exiprom[];
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
 
 #endif	/* _ASM_ARM_SECTIONS_H */
diff --git a/arch/blackfin/include/asm/sections.h b/arch/blackfin/include/asm/sections.h
index fbd408475725..d2abd7a585dd 100644
--- a/arch/blackfin/include/asm/sections.h
+++ b/arch/blackfin/include/asm/sections.h
@@ -7,6 +7,8 @@
 #ifndef _BLACKFIN_SECTIONS_H
 #define _BLACKFIN_SECTIONS_H
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
+
 /* only used when MTD_UCLINUX */
 extern unsigned long memory_mtd_start, memory_mtd_end, mtd_size;
 
@@ -62,6 +64,8 @@ static inline int arch_is_kernel_data(unsigned long addr)
 }
 #define arch_is_kernel_data(addr) arch_is_kernel_data(addr)
 
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
+
 #include <asm-generic/sections.h>
 
 #endif
diff --git a/arch/ia64/include/asm/sections.h b/arch/ia64/include/asm/sections.h
index 2ab2003698ef..3318e3916122 100644
--- a/arch/ia64/include/asm/sections.h
+++ b/arch/ia64/include/asm/sections.h
@@ -6,9 +6,12 @@
  *	David Mosberger-Tang <davidm@hpl.hp.com>
  */
 
+#include <asm-generic/sections.h>
+
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
+
 #include <linux/elf.h>
 #include <linux/uaccess.h>
-#include <asm-generic/sections.h>
 
 extern char __phys_per_cpu_start[];
 #ifdef	CONFIG_SMP
@@ -37,6 +40,6 @@ static inline void *dereference_function_descriptor(void *ptr)
 	return ptr;
 }
 
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
 
 #endif /* _ASM_IA64_SECTIONS_H */
-
diff --git a/arch/powerpc/include/asm/sections.h b/arch/powerpc/include/asm/sections.h
index 7dc006b58369..f226b5bcd27c 100644
--- a/arch/powerpc/include/asm/sections.h
+++ b/arch/powerpc/include/asm/sections.h
@@ -1,11 +1,12 @@
 #ifndef _ASM_POWERPC_SECTIONS_H
 #define _ASM_POWERPC_SECTIONS_H
-#ifdef __KERNEL__
 
-#include <linux/elf.h>
-#include <linux/uaccess.h>
 #include <asm-generic/sections.h>
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
+
+#include <linux/elf.h>
+#include <linux/uaccess.h>
 #ifdef __powerpc64__
 
 extern char __start_interrupts[];
@@ -75,7 +76,7 @@ static inline void *dereference_function_descriptor(void *ptr)
 }
 #endif /* PPC64_ELF_ABI_v1 */
 
-#endif
+#endif /* __powerpc64__ */
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
 
-#endif /* __KERNEL__ */
 #endif	/* _ASM_POWERPC_SECTIONS_H */
diff --git a/arch/sh/include/asm/sections.h b/arch/sh/include/asm/sections.h
index 7a99e6af6372..ad4f9cbd861d 100644
--- a/arch/sh/include/asm/sections.h
+++ b/arch/sh/include/asm/sections.h
@@ -3,9 +3,11 @@
 
 #include <asm-generic/sections.h>
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
 extern long __machvec_start, __machvec_end;
 extern char __uncached_start, __uncached_end;
 extern char __start_eh_frame[], __stop_eh_frame[];
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
 
 #endif /* __ASM_SH_SECTIONS_H */
 
diff --git a/arch/sparc/include/asm/sections.h b/arch/sparc/include/asm/sections.h
index f300d1a9b2b6..b07a2380863e 100644
--- a/arch/sparc/include/asm/sections.h
+++ b/arch/sparc/include/asm/sections.h
@@ -4,10 +4,14 @@
 /* nothing to see, move along */
 #include <asm-generic/sections.h>
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
+
 /* sparc entry point */
 extern char _start[];
 
 extern char __leon_1insn_patch[];
 extern char __leon_1insn_patch_end[];
 
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
+
 #endif
diff --git a/arch/tile/include/asm/sections.h b/arch/tile/include/asm/sections.h
index 86a746243dc8..f9cce7c6d8ba 100644
--- a/arch/tile/include/asm/sections.h
+++ b/arch/tile/include/asm/sections.h
@@ -19,6 +19,8 @@
 
 #include <asm-generic/sections.h>
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
+
 /* Write-once data is writable only till the end of initialization. */
 extern char __w1data_begin[], __w1data_end[];
 
@@ -44,4 +46,6 @@ static inline int arch_is_kernel_data(unsigned long addr)
 		addr < (unsigned long)_end;
 }
 
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
+
 #endif /* _ASM_TILE_SECTIONS_H */
diff --git a/arch/x86/include/asm/sections.h b/arch/x86/include/asm/sections.h
index 13b6cdd0af57..84c7044c82bf 100644
--- a/arch/x86/include/asm/sections.h
+++ b/arch/x86/include/asm/sections.h
@@ -2,13 +2,34 @@
 #define _ASM_X86_SECTIONS_H
 
 #include <asm-generic/sections.h>
-#include <asm/uaccess.h>
+
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
 
 extern char __brk_base[], __brk_limit[];
+
+/*
+ * The exception table consists of triples of addresses relative to the
+ * exception table entry itself. The first address is of an instruction
+ * that is allowed to fault, the second is the target at which the program
+ * should continue. The third is a handler function to deal with the fault
+ * caused by the instruction in the first field.
+ *
+ * All the routines below use bits of fixup code that are out of line
+ * with the main instruction path.  This means when everything is well,
+ * we don't even have to jump over them.  Further, they do not intrude
+ * on our cache or tlb entries.
+ */
+
+struct exception_table_entry {
+	int insn, fixup, handler;
+};
+
 extern struct exception_table_entry __stop___ex_table[];
 
 #if defined(CONFIG_X86_64)
 extern char __end_rodata_hpage_align[];
 #endif
 
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
+
 #endif	/* _ASM_X86_SECTIONS_H */
diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
index a2f253c091e3..d661f28e4e00 100644
--- a/arch/x86/include/asm/uaccess.h
+++ b/arch/x86/include/asm/uaccess.h
@@ -8,6 +8,7 @@
 #include <linux/kasan-checks.h>
 #include <linux/thread_info.h>
 #include <linux/string.h>
+#include <asm/sections.h>
 #include <asm/asm.h>
 #include <asm/page.h>
 #include <asm/smap.h>
@@ -90,23 +91,6 @@ static inline bool __chk_range_not_ok(unsigned long addr, unsigned long size, un
 #define access_ok(type, addr, size) \
 	likely(!__range_not_ok(addr, size, user_addr_max()))
 
-/*
- * The exception table consists of triples of addresses relative to the
- * exception table entry itself. The first address is of an instruction
- * that is allowed to fault, the second is the target at which the program
- * should continue. The third is a handler function to deal with the fault
- * caused by the instruction in the first field.
- *
- * All the routines below use bits of fixup code that are out of line
- * with the main instruction path.  This means when everything is well,
- * we don't even have to jump over them.  Further, they do not intrude
- * on our cache or tlb entries.
- */
-
-struct exception_table_entry {
-	int insn, fixup, handler;
-};
-
 #define ARCH_HAS_RELATIVE_EXTABLE
 
 #define swap_ex_entry_fixup(a, b, tmp, delta)			\
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index af0254c09424..efd51e70a8db 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -1,6 +1,8 @@
 #ifndef _ASM_GENERIC_SECTIONS_H_
 #define _ASM_GENERIC_SECTIONS_H_
 
+#if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
+
 /* References to section boundaries */
 
 #include <linux/compiler.h>
@@ -128,4 +130,6 @@ static inline bool init_section_intersects(void *virt, size_t size)
 	return memory_intersects(__init_begin, __init_end, virt, size);
 }
 
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__) */
+
 #endif /* _ASM_GENERIC_SECTIONS_H_ */
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 05/13] sections.h: add sections header to collect all section info
  2016-07-22 21:24 ` Luis R. Rodriguez
  (?)
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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.

We are now generalizing sections.h in code to enable
avoiding modifying the linker when we want to add new
custom Linux sections but to make this generally useful
we need to ensure all architectures also have their own
asm/sections.h, this is now also used by the custom series
of helpers to an architecture's linker script:

  asm-generic/vmlinux.lds.h.

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 Documentation/DocBook/Makefile        |   3 +-
 Documentation/DocBook/sections.tmpl   | 112 +++++++++++++
 arch/alpha/include/asm/sections.h     |   6 +
 arch/arm64/include/asm/sections.h     |   6 +
 arch/avr32/include/asm/sections.h     |   6 +
 arch/cris/include/asm/sections.h      |   6 +
 arch/h8300/include/asm/sections.h     |   6 +
 arch/hexagon/include/asm/sections.h   |   6 +
 arch/m32r/include/asm/sections.h      |   6 +
 arch/m68k/include/asm/sections.h      |   6 +
 arch/metag/include/asm/sections.h     |   6 +
 arch/mips/include/asm/sections.h      |   6 +
 arch/mn10300/include/asm/sections.h   |   6 +
 arch/nios2/include/asm/sections.h     |   6 +
 arch/openrisc/include/asm/sections.h  |   6 +
 arch/score/include/asm/sections.h     |   6 +
 arch/unicore32/include/asm/sections.h |   6 +
 arch/xtensa/include/asm/sections.h    |   6 +
 include/asm-generic/sections.h        | 300 ++++++++++++++++++++++++++++++++++
 include/asm-generic/vmlinux.lds.h     |  27 +--
 include/linux/sections.h              | 123 ++++++++++++++
 21 files changed, 647 insertions(+), 14 deletions(-)
 create mode 100644 Documentation/DocBook/sections.tmpl
 create mode 100644 arch/alpha/include/asm/sections.h
 create mode 100644 arch/arm64/include/asm/sections.h
 create mode 100644 arch/avr32/include/asm/sections.h
 create mode 100644 arch/cris/include/asm/sections.h
 create mode 100644 arch/h8300/include/asm/sections.h
 create mode 100644 arch/hexagon/include/asm/sections.h
 create mode 100644 arch/m32r/include/asm/sections.h
 create mode 100644 arch/m68k/include/asm/sections.h
 create mode 100644 arch/metag/include/asm/sections.h
 create mode 100644 arch/mips/include/asm/sections.h
 create mode 100644 arch/mn10300/include/asm/sections.h
 create mode 100644 arch/nios2/include/asm/sections.h
 create mode 100644 arch/openrisc/include/asm/sections.h
 create mode 100644 arch/score/include/asm/sections.h
 create mode 100644 arch/unicore32/include/asm/sections.h
 create mode 100644 arch/xtensa/include/asm/sections.h
 create mode 100644 include/linux/sections.h

diff --git a/Documentation/DocBook/Makefile b/Documentation/DocBook/Makefile
index 8e6dd4b14314..1b2ac4731418 100644
--- a/Documentation/DocBook/Makefile
+++ b/Documentation/DocBook/Makefile
@@ -17,7 +17,8 @@ DOCBOOKS := z8530book.xml device-drivers.xml \
 	    80211.xml debugobjects.xml sh.xml regulator.xml \
 	    alsa-driver-api.xml writing-an-alsa-driver.xml \
 	    tracepoint.xml media_api.xml w1.xml \
-	    writing_musb_glue_layer.xml crypto-API.xml iio.xml
+	    writing_musb_glue_layer.xml crypto-API.xml iio.xml \
+	    sections.xml
 
 include Documentation/DocBook/media/Makefile
 
diff --git a/Documentation/DocBook/sections.tmpl b/Documentation/DocBook/sections.tmpl
new file mode 100644
index 000000000000..2d14eb20e99c
--- /dev/null
+++ b/Documentation/DocBook/sections.tmpl
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+	"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
+<set>
+  <setinfo>
+    <title>Linux ELF sections</title>
+    <subtitle>
+      Explains Linux ELF sections
+    </subtitle>
+
+    <copyright>
+      <year>2016</year>
+      <holder>Luis R. Rodriguez</holder>
+    </copyright>
+
+    <authorgroup>
+      <author>
+        <firstname>Luis</firstname>
+        <surname>Rodriguez</surname>
+        <affiliation>
+          <address><email>mcgrof@kernel.org</email></address>
+        </affiliation>
+      </author>
+    </authorgroup>
+
+    <legalnotice>
+      <para>
+        This documentation is free software; you can redistribute
+        it and/or modify it under the terms of the GNU General Public
+        License version 2 as published by the Free Software Foundation.
+      </para>
+      <para>
+        This documentation is distributed in the hope that it will be
+        useful, but WITHOUT ANY WARRANTY; without even the implied
+        warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+        See the GNU General Public License for more details.
+      </para>
+      <para>
+        You should have received a copy of the GNU General Public
+        License along with this documentation; if not, write to the Free
+        Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+        MA 02111-1307 USA
+      </para>
+      <para>
+        For more details see the file COPYING in the source
+        distribution of Linux.
+      </para>
+    </legalnotice>
+
+    <abstract>
+      <para>
+        This book documents the different custom ELF sections used on the Linux
+	kernel and defined on Linux's custom linker script.
+      </para>
+    </abstract>
+  </setinfo>
+  <book id="linux-elf-sections">
+    <bookinfo>
+      <title>Linux kernel ELF sections</title>
+
+      <abstract>
+!Pinclude/asm-generic/sections.h Introduction
+      </abstract>
+    </bookinfo>
+
+      <chapter>
+      <title>Linux kernel sections helpers</title>
+!Pinclude/linux/sections.h Linux section helpers
+!Finclude/linux/sections.h LINUX_SECTION_ALIGNMENT
+!Finclude/linux/sections.h LINUX_SECTION_SIZE
+!Finclude/linux/sections.h LINUX_SECTION_EMPTY
+!Finclude/linux/sections.h LINUX_SECTION_START
+!Finclude/linux/sections.h LINUX_SECTION_END
+!Finclude/linux/sections.h DECLARE_LINUX_SECTION
+!Finclude/linux/sections.h DECLARE_LINUX_SECTION_RO
+!Finclude/linux/sections.h SECTION_TYPE
+      </chapter>
+
+      <chapter>
+      <title>Core Linux kernel sections</title>
+!Pinclude/asm-generic/sections.h Core Linux kernel sections
+!Finclude/asm-generic/sections.h SECTION_RODATA
+!Finclude/asm-generic/sections.h SECTION_TEXT
+!Finclude/asm-generic/sections.h SECTION_DATA
+      </chapter>
+
+      <chapter>
+      <title>Linux .init* sections</title>
+!Pinclude/asm-generic/sections.h Linux init sections
+!Finclude/asm-generic/sections.h SECTION_INIT_DATA
+!Finclude/asm-generic/sections.h SECTION_INIT_RODATA
+!Finclude/asm-generic/sections.h SECTION_INIT_CALL
+      </chapter>
+
+      <chapter>
+      <title>Linux .exit* sections</title>
+!Pinclude/asm-generic/sections.h Linux exit sections
+!Finclude/asm-generic/sections.h SECTION_EXIT
+!Finclude/asm-generic/sections.h SECTION_EXIT_DATA
+!Finclude/asm-generic/sections.h SECTION_EXIT_CALL
+      </chapter>
+
+      <chapter>
+      <title>Linux .ref* sections</title>
+!Pinclude/asm-generic/sections.h Linux references to init sections
+!Finclude/asm-generic/sections.h SECTION_REF
+!Finclude/asm-generic/sections.h SECTION_REF_DATA
+!Finclude/asm-generic/sections.h SECTION_REF_RODATA
+      </chapter>
+
+  </book>
+</set>
diff --git a/arch/alpha/include/asm/sections.h b/arch/alpha/include/asm/sections.h
new file mode 100644
index 000000000000..e58fc679fe15
--- /dev/null
+++ b/arch/alpha/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ALPHA_SECTIONS_H
+#define _ASM_ALPHA_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_ALPHA_SECTIONS_H */
diff --git a/arch/arm64/include/asm/sections.h b/arch/arm64/include/asm/sections.h
new file mode 100644
index 000000000000..cd20ecc157a0
--- /dev/null
+++ b/arch/arm64/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARM64_SECTIONS_H
+#define _ASM_ARM64_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_ARM64_SECTIONS_H */
diff --git a/arch/avr32/include/asm/sections.h b/arch/avr32/include/asm/sections.h
new file mode 100644
index 000000000000..78b3ded34489
--- /dev/null
+++ b/arch/avr32/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_AVR32_SECTIONS_H
+#define _ASM_AVR32_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_AVR32_SECTIONS_H */
diff --git a/arch/cris/include/asm/sections.h b/arch/cris/include/asm/sections.h
new file mode 100644
index 000000000000..802a2433780b
--- /dev/null
+++ b/arch/cris/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_CRIS_SECTIONS_H
+#define _ASM_CRIS_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_CRIS_SECTIONS_H */
diff --git a/arch/h8300/include/asm/sections.h b/arch/h8300/include/asm/sections.h
new file mode 100644
index 000000000000..85ba9501a276
--- /dev/null
+++ b/arch/h8300/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_H8300_SECTIONS_H
+#define _ASM_H8300_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_H8300_SECTIONS_H */
diff --git a/arch/hexagon/include/asm/sections.h b/arch/hexagon/include/asm/sections.h
new file mode 100644
index 000000000000..f905cf754efd
--- /dev/null
+++ b/arch/hexagon/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_HEXAGON_SECTIONS_H
+#define _ASM_HEXAGON_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_HEXAGON_SECTIONS_H */
diff --git a/arch/m32r/include/asm/sections.h b/arch/m32r/include/asm/sections.h
new file mode 100644
index 000000000000..25cfc2068443
--- /dev/null
+++ b/arch/m32r/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_M32R_SECTIONS_H
+#define _ASM_M32R_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_M32R_SECTIONS_H */
diff --git a/arch/m68k/include/asm/sections.h b/arch/m68k/include/asm/sections.h
new file mode 100644
index 000000000000..d64967ecfec6
--- /dev/null
+++ b/arch/m68k/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_M68K_SECTIONS_H
+#define _ASM_M68K_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_M68K_SECTIONS_H */
diff --git a/arch/metag/include/asm/sections.h b/arch/metag/include/asm/sections.h
new file mode 100644
index 000000000000..bb76d9a1ec20
--- /dev/null
+++ b/arch/metag/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_METAG_SECTIONS_H
+#define _ASM_METAG_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_METAG_SECTIONS_H */
diff --git a/arch/mips/include/asm/sections.h b/arch/mips/include/asm/sections.h
new file mode 100644
index 000000000000..425b508acfc7
--- /dev/null
+++ b/arch/mips/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MIPS_SECTIONS_H
+#define _ASM_MIPS_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_MIPS_SECTIONS_H */
diff --git a/arch/mn10300/include/asm/sections.h b/arch/mn10300/include/asm/sections.h
new file mode 100644
index 000000000000..61a62637a860
--- /dev/null
+++ b/arch/mn10300/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MN10300_SECTIONS_H
+#define _ASM_MN10300_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_MN10300_SECTIONS_H */
diff --git a/arch/nios2/include/asm/sections.h b/arch/nios2/include/asm/sections.h
new file mode 100644
index 000000000000..b6fc5d8e2e77
--- /dev/null
+++ b/arch/nios2/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_NIOS2_SECTIONS_H
+#define _ASM_NIOS2_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_NIOS2_SECTIONS_H */
diff --git a/arch/openrisc/include/asm/sections.h b/arch/openrisc/include/asm/sections.h
new file mode 100644
index 000000000000..561ee5ac5ead
--- /dev/null
+++ b/arch/openrisc/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_OPENRISC_SECTIONS_H
+#define _ASM_OPENRISC_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_OPENRISC_SECTIONS_H */
diff --git a/arch/score/include/asm/sections.h b/arch/score/include/asm/sections.h
new file mode 100644
index 000000000000..9441d23af005
--- /dev/null
+++ b/arch/score/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SCORE_SECTIONS_H
+#define _ASM_SCORE_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_SCORE_SECTIONS_H */
diff --git a/arch/unicore32/include/asm/sections.h b/arch/unicore32/include/asm/sections.h
new file mode 100644
index 000000000000..ec4cd27c85be
--- /dev/null
+++ b/arch/unicore32/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_UNICORE32_SECTIONS_H
+#define _ASM_UNICORE32_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_UNICORE32_SECTIONS_H */
diff --git a/arch/xtensa/include/asm/sections.h b/arch/xtensa/include/asm/sections.h
new file mode 100644
index 000000000000..ab1176a674c9
--- /dev/null
+++ b/arch/xtensa/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_XTENSA_SECTIONS_H
+#define _ASM_XTENSA_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_XTENSA_SECTIONS_H */
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index efd51e70a8db..cd4313c3edf8 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -1,6 +1,306 @@
 #ifndef _ASM_GENERIC_SECTIONS_H_
 #define _ASM_GENERIC_SECTIONS_H_
 
+/**
+ * DOC: Introduction
+ *
+ * The Linux vmlinux binary uses a custom linker script which adds
+ * some custom specialized ELF sections. This aims to document those
+ * sections. Each section must document the goal of the section, and
+ * address concurrency considerations when applicable.
+ */
+
+/**
+ * DOC: Core Linux kernel sections
+ *
+ * These are the core Linux kernel sections.
+ */
+
+/**
+ * SECTION_RODATA - read only data
+ *
+ * Macro name for code which must be protected from write access.
+ */
+#define SECTION_RODATA			.rodata
+
+/**
+ * SECTION_TEXT - kernel code execution section, read-only
+ *
+ * Macro name used to annotate code (functions) used during regular
+ * kernel run time. This is combined with SECTION_RODATA, only this
+ * section also gets execution allowed.
+ *
+ */
+#define SECTION_TEXT			.text
+
+/**
+ * SECTION_DATA - for read-write data
+ *
+ * Macro name for read-write data.
+ */
+#define SECTION_DATA			.data
+
+/**
+ * DOC: Linux init sections
+ *
+ * These sections are used for code and data structures used during boot or
+ * module initialization. On architectures that support it (x86, x86_64), all
+ * this code is freed up by the kernel right before the fist userspace init
+ * process is called when built-in to the kernel, and if modular it is freed
+ * after module initialization. Since the code is freed so early, in theory
+ * there should be no races against freeing this code with other CPUs. Init
+ * section code and data structures should never be exported with
+ * EXPORT_SYMBOL*() as the code will quickly become unavailable to the kernel
+ * after bootup.
+ */
+
+/**
+ * SECTION_INIT - boot initialization code
+ *
+ * Macro name used to annotate code (functions) used only during boot or driver
+ * initialization.
+ *
+ */
+#define SECTION_INIT			.init.text
+
+/**
+ * SECTION_INIT_DATA - boot initialization data
+ *
+ * Macro name used to annotate data structures used only during boot or driver
+ * initialization.
+ */
+#define SECTION_INIT_DATA		.init.data
+
+/**
+ * SECTION_INIT_RODATA - boot read-only initialization data
+ *
+ * Macro name used to annotate read-only code (functions) used only during boot
+ * or driver initialization.
+ */
+#define SECTION_INIT_RODATA		.init.rodata
+
+/**
+ * SECTION_INIT_CALL - special init call
+ *
+ * Special macro name used to annotate subsystem init call. These calls are
+ * are now grouped by functionality into separate subsections. Ordering inside
+ * the subsections is determined by link order.
+ */
+#define SECTION_INIT_CALL		.initcall
+
+/**
+ * DOC: Linux exit sections
+ *
+ * These sections are used to declare a functions and data structures which
+ * are only required on exit, the function or data structure will be dropped
+ * if the code declaring this section is not compiled as a module on
+ * architectures that support this (x86, x86_64). There is no special case
+ * handling for this code when built-in to the kernel.
+ */
+
+/**
+ * SECTION_EXIT - module exit code
+ *
+ * Macro name used to annotate code (functions) used only during module
+ * unload.
+ */
+#define SECTION_EXIT			.exit.text
+
+/**
+ * SECTION_EXIT_DATA - module exit data structures
+ *
+ * Macro name used to annotate data structures used only during module
+ * unload.
+ */
+#define SECTION_EXIT_DATA		.exit.data
+
+/**
+ * SECTION_EXIT_CALL - special exit call
+ *
+ * Special macro name used to annotate an exit exit routine, order
+ * is important and maintained by link order.
+ */
+#define SECTION_EXIT_CALL		.exitcall.exit
+
+/**
+ * DOC: Linux references to init sections
+ *
+ * These sections are used to teach modpost to not warn about possible
+ * misuses of init section code from other sections. If you use this
+ * your use case should document why you are certain such use of init
+ * sectioned code is valid. For more details refer to include/linux/init.h
+ * __ref, __refdata, and __refconst documentation.
+ */
+
+/**
+ * SECTION_REF - code referencing init is valid
+ *
+ * Macro name used to annotate that code (functions) declared with this section
+ * has been vetteed as valid for its reference or use of other code (functions)
+ * or data structures which are part of the init sections.
+ */
+#define SECTION_REF			.ref.text
+
+/**
+ * SECTION_REF_DATA - reference data structure are valid
+ *
+ * Macro name used to annotate data structures declared with this section have
+ * been vetteed for its reference or use of other code (functions) or data
+ * structures part of the init sections.
+ */
+#define SECTION_REF_DATA		.ref.data
+
+/**
+ * SECTION_REF_RODATA - const code or data structure referencing init is valid
+ *
+ * Macro name used to annotate const code (functions) const data structures
+ * which has been vetteed for its reference or use of other code (functions)
+ * or data structures part of the init sections.
+ */
+#define SECTION_REF_RODATA		.ref.rodata
+
+#define SECTION_ORDER_ANY	any
+
+/*
+ * These section _ALL() helpers are for use on linker scripts and helpers
+ */
+#define SECTION_ALL(__section)						\
+	__section##.*
+#define SECTION_TYPE_ALL(__section, __type)				\
+	__section##.##__type##.*
+
+/* Can be used on foo.S for instance */
+#ifndef __section_type_asmtype
+# define __section_type_asmtype(__section, __type, __name,		\
+			        __level, __flags, __asm_type)		\
+	.section __section.__type.__name.__level, __flags, __asm_type
+#endif
+
+#ifndef __section_type
+# define __section_type(__section, __type, __name, __level, __flags)	\
+	.section __section.__type.__name.__level, __flags
+#endif
+
+#ifndef __push_section_type
+# define __push_section_type(__section, __type, __name, __level, __flags) \
+	.pushsection __section.__type.__name.__level, __flags
+#endif
+
+#ifdef __KERNEL__
+#include <linux/stringify.h>
+#endif
+
+#if defined(__ASSEMBLER__) || defined(__ASSEMBLY__)
+
+# ifdef LINKER_SCRIPT
+
+#  ifndef SECTION_TYPE
+#   define SECTION_TYPE(__section, __type, __name, __level)		\
+	__section.__type.__name.__level
+#  endif
+
+# else
+
+#  ifndef push_section_type
+#   define push_section_type(__section, __type, __name, __level, __flags) \
+	 __push_section_type(__section, __type, __name,			  \
+			     __level, __stringify(__flags))
+#  endif
+
+#  ifndef section_type
+#   define section_type(__section, __type, __name, __level, __flags)	\
+	__section_type(__section, __type, __name,			\
+		       __level, __stringify(__flags))
+#  endif
+
+#  ifndef section_type_asmtype
+#   define section_type_asmtype(__section, __type, __name,		\
+			        __level, __flags, __asmtype)		\
+	__section_type_asmtype(__section, __type, __name, __level,	\
+			       __stringify(__flags), __asmtype)
+#  endif
+
+#  ifndef SECTION_TYPE
+#   define SECTION_TYPE(__section, __type, __name, __level)		\
+	push_section_type(__section, __type, __name, __level, )
+#  endif
+
+# endif /* LINKER_SCRIPT */
+#else /* defined(__ASSEMBLER__) || defined(__ASSEMBLY__) */
+
+/*
+ * 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
+
+# ifndef section_type
+#  define section_type(__section, __type, __name, __level, __flags)	\
+	__stringify(__section_type(__section, __type, __name,		\
+				   __level, __stringify(__flags)))	\
+	ASM_CMD_SEP
+# endif
+
+/*
+ * Some architectures (arm, and avr32 are two examples on kprobes) seem
+ * currently explicitly specify the asm type [0] -- this can be any of
+ * the optional constants on ELF:
+ *
+ * @progbits - section contains data
+ * @nobits - section does not contain data (i.e., section only occupies space)
+ * @note - section contains data which is used by things other than the program
+ * @init_array - section contains an array of pointers to init functions
+ * @fini_array - section contains an array of pointers to finish functions
+ * @preinit_array - section contains an array of pointers to pre-init functions
+ *
+ * ARM requires % instead of @.
+ *
+ * At least as per nasm (x86/x86_64 only), in the absence of qualifiers the
+ * defaults are as follows:
+ *
+ * section .text    progbits  alloc   exec    nowrite  align\x16
+ * section .rodata  progbits  alloc   noexec  nowrite  align=4
+ * section .lrodata progbits  alloc   noexec  nowrite  align=4
+ * section .data    progbits  alloc   noexec  write    align=4
+ * section .ldata   progbits  alloc   noexec  write    align=4
+ * section .bss     nobits    alloc   noexec  write    align=4
+ * section .lbss    nobits    alloc   noexec  write    align=4
+ * section .tdata   progbits  alloc   noexec  write    align=4    tls
+ * section .tbss    nobits    alloc   noexec  write    align=4    tls
+ * section .comment progbits  noalloc noexec  nowrite  align=1
+ * section other    progbits  alloc   noexec  nowrite  align=1
+ *
+ * gas should have sensible defaults for architectures...
+ *
+ * [0] http://www.nasm.us/doc/nasmdoc7.html
+ */
+# ifndef section_type_asmtype
+#  define section_type_asmtype(__section, __type, __name, __level,	\
+			     __flags, __asmtype)			\
+	__stringify(__section_type_asmtype(__section, __type,		\
+					   __name, __level,		\
+					   __stringify(__flags),	\
+					   asmtype))			\
+	ASM_CMD_SEP
+# endif
+
+# ifndef push_section_type
+#  define push_section_type(__section, __type, __name, __level, __flags)	\
+	__stringify(__push_section_type(__section, __type,		\
+					__name,	__level,		\
+					__stringify(__flags)))		\
+	ASM_CMD_SEP
+# endif
+
+#endif /* defined(__ASSEMBLER__) || defined(__ASSEMBLY__) */
+
 #if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
 
 /* References to section boundaries */
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 24563970ff7b..0042f30ff34b 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -55,6 +55,7 @@
 #endif
 
 #include <linux/export.h>
+#include <asm/sections.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
diff --git a/include/linux/sections.h b/include/linux/sections.h
new file mode 100644
index 000000000000..118c46f884a7
--- /dev/null
+++ b/include/linux/sections.h
@@ -0,0 +1,123 @@
+#ifndef _LINUX_SECTIONS_H
+#define _LINUX_SECTIONS_H
+/*
+ * Linux de-facto sections
+ *
+ * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
+ *
+ * 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/.
+ */
+
+#ifdef __KERNEL__
+# include <asm/sections.h>
+#endif /* __KERNEL__ */
+
+#ifndef __ASSEMBLY__
+
+/**
+ * DOC: Linux section helpers
+ *
+ * Set of common helpers which can be used to against custom Linux sections.
+ */
+
+/**
+ * LINUX_SECTION_ALIGNMENT - get section alignment
+ *
+ * @name: section name
+ *
+ * Gives you the alignment for the section.
+ */
+#define LINUX_SECTION_ALIGNMENT(name)	__alignof__(*name)
+
+/**
+ * LINUX_SECTION_SIZE - get number of entries in the section
+ *
+ * @name: section name
+ *
+ * This gives you the number of entries in the section.
+ * Example usage:
+ *
+ *   unsigned int num_frobs = LINUX_SECTION_SIZE(frobnicator_fns);
+ */
+#define LINUX_SECTION_SIZE(name)	((name##__end) - (name))
+
+/**
+ * LINUX_SECTION_EMPTY - check if section has no entries
+ *
+ * @name: section name
+ *
+ * Returns true if section is emtpy.
+ *
+ *   bool is_empty = LINUX_SECTION_EMPTY(frobnicator_fns);
+ */
+#define LINUX_SECTION_EMPTY(name)	(LINUX_SECTION_SIZE(name) = 0)
+
+/**
+ * LINUX_SECTION_START - get address of start of section
+ *
+ * @name: section name
+ *
+ * This gives you the start address of the section.
+ * This should give you the address of the first entry.
+ *
+ */
+#define LINUX_SECTION_START(name)	name
+
+/**
+ * LINUX_SECTION_END - get address of end of the section
+ *
+ * @name: section name
+ *
+ * This gives you the end address of the section.
+ * This should give you the address of the end of the
+ * section. This will match the start address if the
+ * section is empty.
+ */
+#define LINUX_SECTION_END(name)	name##__end
+
+/**
+ * DECLARE_LINUX_SECTION - Declares a custom Linux section
+ *
+ * @type: type of custom Linux section
+ * @name: custom section name
+ *
+ * Declares a read-write custom Linux section
+ */
+#define DECLARE_LINUX_SECTION(type, name)				\
+	 extern type name[], name##__end[];
+
+/**
+ * DECLARE_LINUX_SECTION_RO - Declares a read-only custom Linux section
+ *
+ * @type: type of custom Linux section
+ * @name: custom section name
+ *
+ * Declares a read-only custom Linux section
+ */
+#define DECLARE_LINUX_SECTION_RO(type, name)				\
+	 extern const type name[], name##__end[];
+
+#define __SECTION_TYPE(section, type, name, level)			\
+	#section "." #type "." #name "." #level
+
+/**
+ * SECTION_TYPE - helper to construct a custom section type name
+ *
+ * @section: known de facto section, in asm-generic/sections.h
+ * @type: type of Linux section
+ * @name: custom section name
+ * @level: order level, used to help sort the section entries. The value
+ *	used should be a digit. Since ELF sections are strings there is
+ *	no technical restriction on the length of the number of digits
+ *	used.
+ *
+ * Helper to construct the name of a custom section type.
+ */
+#define SECTION_TYPE(section, type, name, level)                       	\
+	__SECTION_TYPE(section, type, name, level)
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _LINUX_SECTIONS_H */
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 05/13] sections.h: add sections header to collect all section info
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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.

We are now generalizing sections.h in code to enable
avoiding modifying the linker when we want to add new
custom Linux sections but to make this generally useful
we need to ensure all architectures also have their own
asm/sections.h, this is now also used by the custom series
of helpers to an architecture's linker script:

  asm-generic/vmlinux.lds.h.

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 Documentation/DocBook/Makefile        |   3 +-
 Documentation/DocBook/sections.tmpl   | 112 +++++++++++++
 arch/alpha/include/asm/sections.h     |   6 +
 arch/arm64/include/asm/sections.h     |   6 +
 arch/avr32/include/asm/sections.h     |   6 +
 arch/cris/include/asm/sections.h      |   6 +
 arch/h8300/include/asm/sections.h     |   6 +
 arch/hexagon/include/asm/sections.h   |   6 +
 arch/m32r/include/asm/sections.h      |   6 +
 arch/m68k/include/asm/sections.h      |   6 +
 arch/metag/include/asm/sections.h     |   6 +
 arch/mips/include/asm/sections.h      |   6 +
 arch/mn10300/include/asm/sections.h   |   6 +
 arch/nios2/include/asm/sections.h     |   6 +
 arch/openrisc/include/asm/sections.h  |   6 +
 arch/score/include/asm/sections.h     |   6 +
 arch/unicore32/include/asm/sections.h |   6 +
 arch/xtensa/include/asm/sections.h    |   6 +
 include/asm-generic/sections.h        | 300 ++++++++++++++++++++++++++++++++++
 include/asm-generic/vmlinux.lds.h     |  27 +--
 include/linux/sections.h              | 123 ++++++++++++++
 21 files changed, 647 insertions(+), 14 deletions(-)
 create mode 100644 Documentation/DocBook/sections.tmpl
 create mode 100644 arch/alpha/include/asm/sections.h
 create mode 100644 arch/arm64/include/asm/sections.h
 create mode 100644 arch/avr32/include/asm/sections.h
 create mode 100644 arch/cris/include/asm/sections.h
 create mode 100644 arch/h8300/include/asm/sections.h
 create mode 100644 arch/hexagon/include/asm/sections.h
 create mode 100644 arch/m32r/include/asm/sections.h
 create mode 100644 arch/m68k/include/asm/sections.h
 create mode 100644 arch/metag/include/asm/sections.h
 create mode 100644 arch/mips/include/asm/sections.h
 create mode 100644 arch/mn10300/include/asm/sections.h
 create mode 100644 arch/nios2/include/asm/sections.h
 create mode 100644 arch/openrisc/include/asm/sections.h
 create mode 100644 arch/score/include/asm/sections.h
 create mode 100644 arch/unicore32/include/asm/sections.h
 create mode 100644 arch/xtensa/include/asm/sections.h
 create mode 100644 include/linux/sections.h

diff --git a/Documentation/DocBook/Makefile b/Documentation/DocBook/Makefile
index 8e6dd4b14314..1b2ac4731418 100644
--- a/Documentation/DocBook/Makefile
+++ b/Documentation/DocBook/Makefile
@@ -17,7 +17,8 @@ DOCBOOKS := z8530book.xml device-drivers.xml \
 	    80211.xml debugobjects.xml sh.xml regulator.xml \
 	    alsa-driver-api.xml writing-an-alsa-driver.xml \
 	    tracepoint.xml media_api.xml w1.xml \
-	    writing_musb_glue_layer.xml crypto-API.xml iio.xml
+	    writing_musb_glue_layer.xml crypto-API.xml iio.xml \
+	    sections.xml
 
 include Documentation/DocBook/media/Makefile
 
diff --git a/Documentation/DocBook/sections.tmpl b/Documentation/DocBook/sections.tmpl
new file mode 100644
index 000000000000..2d14eb20e99c
--- /dev/null
+++ b/Documentation/DocBook/sections.tmpl
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+	"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
+<set>
+  <setinfo>
+    <title>Linux ELF sections</title>
+    <subtitle>
+      Explains Linux ELF sections
+    </subtitle>
+
+    <copyright>
+      <year>2016</year>
+      <holder>Luis R. Rodriguez</holder>
+    </copyright>
+
+    <authorgroup>
+      <author>
+        <firstname>Luis</firstname>
+        <surname>Rodriguez</surname>
+        <affiliation>
+          <address><email>mcgrof@kernel.org</email></address>
+        </affiliation>
+      </author>
+    </authorgroup>
+
+    <legalnotice>
+      <para>
+        This documentation is free software; you can redistribute
+        it and/or modify it under the terms of the GNU General Public
+        License version 2 as published by the Free Software Foundation.
+      </para>
+      <para>
+        This documentation is distributed in the hope that it will be
+        useful, but WITHOUT ANY WARRANTY; without even the implied
+        warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+        See the GNU General Public License for more details.
+      </para>
+      <para>
+        You should have received a copy of the GNU General Public
+        License along with this documentation; if not, write to the Free
+        Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+        MA 02111-1307 USA
+      </para>
+      <para>
+        For more details see the file COPYING in the source
+        distribution of Linux.
+      </para>
+    </legalnotice>
+
+    <abstract>
+      <para>
+        This book documents the different custom ELF sections used on the Linux
+	kernel and defined on Linux's custom linker script.
+      </para>
+    </abstract>
+  </setinfo>
+  <book id="linux-elf-sections">
+    <bookinfo>
+      <title>Linux kernel ELF sections</title>
+
+      <abstract>
+!Pinclude/asm-generic/sections.h Introduction
+      </abstract>
+    </bookinfo>
+
+      <chapter>
+      <title>Linux kernel sections helpers</title>
+!Pinclude/linux/sections.h Linux section helpers
+!Finclude/linux/sections.h LINUX_SECTION_ALIGNMENT
+!Finclude/linux/sections.h LINUX_SECTION_SIZE
+!Finclude/linux/sections.h LINUX_SECTION_EMPTY
+!Finclude/linux/sections.h LINUX_SECTION_START
+!Finclude/linux/sections.h LINUX_SECTION_END
+!Finclude/linux/sections.h DECLARE_LINUX_SECTION
+!Finclude/linux/sections.h DECLARE_LINUX_SECTION_RO
+!Finclude/linux/sections.h SECTION_TYPE
+      </chapter>
+
+      <chapter>
+      <title>Core Linux kernel sections</title>
+!Pinclude/asm-generic/sections.h Core Linux kernel sections
+!Finclude/asm-generic/sections.h SECTION_RODATA
+!Finclude/asm-generic/sections.h SECTION_TEXT
+!Finclude/asm-generic/sections.h SECTION_DATA
+      </chapter>
+
+      <chapter>
+      <title>Linux .init* sections</title>
+!Pinclude/asm-generic/sections.h Linux init sections
+!Finclude/asm-generic/sections.h SECTION_INIT_DATA
+!Finclude/asm-generic/sections.h SECTION_INIT_RODATA
+!Finclude/asm-generic/sections.h SECTION_INIT_CALL
+      </chapter>
+
+      <chapter>
+      <title>Linux .exit* sections</title>
+!Pinclude/asm-generic/sections.h Linux exit sections
+!Finclude/asm-generic/sections.h SECTION_EXIT
+!Finclude/asm-generic/sections.h SECTION_EXIT_DATA
+!Finclude/asm-generic/sections.h SECTION_EXIT_CALL
+      </chapter>
+
+      <chapter>
+      <title>Linux .ref* sections</title>
+!Pinclude/asm-generic/sections.h Linux references to init sections
+!Finclude/asm-generic/sections.h SECTION_REF
+!Finclude/asm-generic/sections.h SECTION_REF_DATA
+!Finclude/asm-generic/sections.h SECTION_REF_RODATA
+      </chapter>
+
+  </book>
+</set>
diff --git a/arch/alpha/include/asm/sections.h b/arch/alpha/include/asm/sections.h
new file mode 100644
index 000000000000..e58fc679fe15
--- /dev/null
+++ b/arch/alpha/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ALPHA_SECTIONS_H
+#define _ASM_ALPHA_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_ALPHA_SECTIONS_H */
diff --git a/arch/arm64/include/asm/sections.h b/arch/arm64/include/asm/sections.h
new file mode 100644
index 000000000000..cd20ecc157a0
--- /dev/null
+++ b/arch/arm64/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARM64_SECTIONS_H
+#define _ASM_ARM64_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_ARM64_SECTIONS_H */
diff --git a/arch/avr32/include/asm/sections.h b/arch/avr32/include/asm/sections.h
new file mode 100644
index 000000000000..78b3ded34489
--- /dev/null
+++ b/arch/avr32/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_AVR32_SECTIONS_H
+#define _ASM_AVR32_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_AVR32_SECTIONS_H */
diff --git a/arch/cris/include/asm/sections.h b/arch/cris/include/asm/sections.h
new file mode 100644
index 000000000000..802a2433780b
--- /dev/null
+++ b/arch/cris/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_CRIS_SECTIONS_H
+#define _ASM_CRIS_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_CRIS_SECTIONS_H */
diff --git a/arch/h8300/include/asm/sections.h b/arch/h8300/include/asm/sections.h
new file mode 100644
index 000000000000..85ba9501a276
--- /dev/null
+++ b/arch/h8300/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_H8300_SECTIONS_H
+#define _ASM_H8300_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_H8300_SECTIONS_H */
diff --git a/arch/hexagon/include/asm/sections.h b/arch/hexagon/include/asm/sections.h
new file mode 100644
index 000000000000..f905cf754efd
--- /dev/null
+++ b/arch/hexagon/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_HEXAGON_SECTIONS_H
+#define _ASM_HEXAGON_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_HEXAGON_SECTIONS_H */
diff --git a/arch/m32r/include/asm/sections.h b/arch/m32r/include/asm/sections.h
new file mode 100644
index 000000000000..25cfc2068443
--- /dev/null
+++ b/arch/m32r/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_M32R_SECTIONS_H
+#define _ASM_M32R_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_M32R_SECTIONS_H */
diff --git a/arch/m68k/include/asm/sections.h b/arch/m68k/include/asm/sections.h
new file mode 100644
index 000000000000..d64967ecfec6
--- /dev/null
+++ b/arch/m68k/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_M68K_SECTIONS_H
+#define _ASM_M68K_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_M68K_SECTIONS_H */
diff --git a/arch/metag/include/asm/sections.h b/arch/metag/include/asm/sections.h
new file mode 100644
index 000000000000..bb76d9a1ec20
--- /dev/null
+++ b/arch/metag/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_METAG_SECTIONS_H
+#define _ASM_METAG_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_METAG_SECTIONS_H */
diff --git a/arch/mips/include/asm/sections.h b/arch/mips/include/asm/sections.h
new file mode 100644
index 000000000000..425b508acfc7
--- /dev/null
+++ b/arch/mips/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MIPS_SECTIONS_H
+#define _ASM_MIPS_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_MIPS_SECTIONS_H */
diff --git a/arch/mn10300/include/asm/sections.h b/arch/mn10300/include/asm/sections.h
new file mode 100644
index 000000000000..61a62637a860
--- /dev/null
+++ b/arch/mn10300/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MN10300_SECTIONS_H
+#define _ASM_MN10300_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_MN10300_SECTIONS_H */
diff --git a/arch/nios2/include/asm/sections.h b/arch/nios2/include/asm/sections.h
new file mode 100644
index 000000000000..b6fc5d8e2e77
--- /dev/null
+++ b/arch/nios2/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_NIOS2_SECTIONS_H
+#define _ASM_NIOS2_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_NIOS2_SECTIONS_H */
diff --git a/arch/openrisc/include/asm/sections.h b/arch/openrisc/include/asm/sections.h
new file mode 100644
index 000000000000..561ee5ac5ead
--- /dev/null
+++ b/arch/openrisc/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_OPENRISC_SECTIONS_H
+#define _ASM_OPENRISC_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_OPENRISC_SECTIONS_H */
diff --git a/arch/score/include/asm/sections.h b/arch/score/include/asm/sections.h
new file mode 100644
index 000000000000..9441d23af005
--- /dev/null
+++ b/arch/score/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SCORE_SECTIONS_H
+#define _ASM_SCORE_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_SCORE_SECTIONS_H */
diff --git a/arch/unicore32/include/asm/sections.h b/arch/unicore32/include/asm/sections.h
new file mode 100644
index 000000000000..ec4cd27c85be
--- /dev/null
+++ b/arch/unicore32/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_UNICORE32_SECTIONS_H
+#define _ASM_UNICORE32_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_UNICORE32_SECTIONS_H */
diff --git a/arch/xtensa/include/asm/sections.h b/arch/xtensa/include/asm/sections.h
new file mode 100644
index 000000000000..ab1176a674c9
--- /dev/null
+++ b/arch/xtensa/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_XTENSA_SECTIONS_H
+#define _ASM_XTENSA_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_XTENSA_SECTIONS_H */
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index efd51e70a8db..cd4313c3edf8 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -1,6 +1,306 @@
 #ifndef _ASM_GENERIC_SECTIONS_H_
 #define _ASM_GENERIC_SECTIONS_H_
 
+/**
+ * DOC: Introduction
+ *
+ * The Linux vmlinux binary uses a custom linker script which adds
+ * some custom specialized ELF sections. This aims to document those
+ * sections. Each section must document the goal of the section, and
+ * address concurrency considerations when applicable.
+ */
+
+/**
+ * DOC: Core Linux kernel sections
+ *
+ * These are the core Linux kernel sections.
+ */
+
+/**
+ * SECTION_RODATA - read only data
+ *
+ * Macro name for code which must be protected from write access.
+ */
+#define SECTION_RODATA			.rodata
+
+/**
+ * SECTION_TEXT - kernel code execution section, read-only
+ *
+ * Macro name used to annotate code (functions) used during regular
+ * kernel run time. This is combined with SECTION_RODATA, only this
+ * section also gets execution allowed.
+ *
+ */
+#define SECTION_TEXT			.text
+
+/**
+ * SECTION_DATA - for read-write data
+ *
+ * Macro name for read-write data.
+ */
+#define SECTION_DATA			.data
+
+/**
+ * DOC: Linux init sections
+ *
+ * These sections are used for code and data structures used during boot or
+ * module initialization. On architectures that support it (x86, x86_64), all
+ * this code is freed up by the kernel right before the fist userspace init
+ * process is called when built-in to the kernel, and if modular it is freed
+ * after module initialization. Since the code is freed so early, in theory
+ * there should be no races against freeing this code with other CPUs. Init
+ * section code and data structures should never be exported with
+ * EXPORT_SYMBOL*() as the code will quickly become unavailable to the kernel
+ * after bootup.
+ */
+
+/**
+ * SECTION_INIT - boot initialization code
+ *
+ * Macro name used to annotate code (functions) used only during boot or driver
+ * initialization.
+ *
+ */
+#define SECTION_INIT			.init.text
+
+/**
+ * SECTION_INIT_DATA - boot initialization data
+ *
+ * Macro name used to annotate data structures used only during boot or driver
+ * initialization.
+ */
+#define SECTION_INIT_DATA		.init.data
+
+/**
+ * SECTION_INIT_RODATA - boot read-only initialization data
+ *
+ * Macro name used to annotate read-only code (functions) used only during boot
+ * or driver initialization.
+ */
+#define SECTION_INIT_RODATA		.init.rodata
+
+/**
+ * SECTION_INIT_CALL - special init call
+ *
+ * Special macro name used to annotate subsystem init call. These calls are
+ * are now grouped by functionality into separate subsections. Ordering inside
+ * the subsections is determined by link order.
+ */
+#define SECTION_INIT_CALL		.initcall
+
+/**
+ * DOC: Linux exit sections
+ *
+ * These sections are used to declare a functions and data structures which
+ * are only required on exit, the function or data structure will be dropped
+ * if the code declaring this section is not compiled as a module on
+ * architectures that support this (x86, x86_64). There is no special case
+ * handling for this code when built-in to the kernel.
+ */
+
+/**
+ * SECTION_EXIT - module exit code
+ *
+ * Macro name used to annotate code (functions) used only during module
+ * unload.
+ */
+#define SECTION_EXIT			.exit.text
+
+/**
+ * SECTION_EXIT_DATA - module exit data structures
+ *
+ * Macro name used to annotate data structures used only during module
+ * unload.
+ */
+#define SECTION_EXIT_DATA		.exit.data
+
+/**
+ * SECTION_EXIT_CALL - special exit call
+ *
+ * Special macro name used to annotate an exit exit routine, order
+ * is important and maintained by link order.
+ */
+#define SECTION_EXIT_CALL		.exitcall.exit
+
+/**
+ * DOC: Linux references to init sections
+ *
+ * These sections are used to teach modpost to not warn about possible
+ * misuses of init section code from other sections. If you use this
+ * your use case should document why you are certain such use of init
+ * sectioned code is valid. For more details refer to include/linux/init.h
+ * __ref, __refdata, and __refconst documentation.
+ */
+
+/**
+ * SECTION_REF - code referencing init is valid
+ *
+ * Macro name used to annotate that code (functions) declared with this section
+ * has been vetteed as valid for its reference or use of other code (functions)
+ * or data structures which are part of the init sections.
+ */
+#define SECTION_REF			.ref.text
+
+/**
+ * SECTION_REF_DATA - reference data structure are valid
+ *
+ * Macro name used to annotate data structures declared with this section have
+ * been vetteed for its reference or use of other code (functions) or data
+ * structures part of the init sections.
+ */
+#define SECTION_REF_DATA		.ref.data
+
+/**
+ * SECTION_REF_RODATA - const code or data structure referencing init is valid
+ *
+ * Macro name used to annotate const code (functions) const data structures
+ * which has been vetteed for its reference or use of other code (functions)
+ * or data structures part of the init sections.
+ */
+#define SECTION_REF_RODATA		.ref.rodata
+
+#define SECTION_ORDER_ANY	any
+
+/*
+ * These section _ALL() helpers are for use on linker scripts and helpers
+ */
+#define SECTION_ALL(__section)						\
+	__section##.*
+#define SECTION_TYPE_ALL(__section, __type)				\
+	__section##.##__type##.*
+
+/* Can be used on foo.S for instance */
+#ifndef __section_type_asmtype
+# define __section_type_asmtype(__section, __type, __name,		\
+			        __level, __flags, __asm_type)		\
+	.section __section.__type.__name.__level, __flags, __asm_type
+#endif
+
+#ifndef __section_type
+# define __section_type(__section, __type, __name, __level, __flags)	\
+	.section __section.__type.__name.__level, __flags
+#endif
+
+#ifndef __push_section_type
+# define __push_section_type(__section, __type, __name, __level, __flags) \
+	.pushsection __section.__type.__name.__level, __flags
+#endif
+
+#ifdef __KERNEL__
+#include <linux/stringify.h>
+#endif
+
+#if defined(__ASSEMBLER__) || defined(__ASSEMBLY__)
+
+# ifdef LINKER_SCRIPT
+
+#  ifndef SECTION_TYPE
+#   define SECTION_TYPE(__section, __type, __name, __level)		\
+	__section.__type.__name.__level
+#  endif
+
+# else
+
+#  ifndef push_section_type
+#   define push_section_type(__section, __type, __name, __level, __flags) \
+	 __push_section_type(__section, __type, __name,			  \
+			     __level, __stringify(__flags))
+#  endif
+
+#  ifndef section_type
+#   define section_type(__section, __type, __name, __level, __flags)	\
+	__section_type(__section, __type, __name,			\
+		       __level, __stringify(__flags))
+#  endif
+
+#  ifndef section_type_asmtype
+#   define section_type_asmtype(__section, __type, __name,		\
+			        __level, __flags, __asmtype)		\
+	__section_type_asmtype(__section, __type, __name, __level,	\
+			       __stringify(__flags), __asmtype)
+#  endif
+
+#  ifndef SECTION_TYPE
+#   define SECTION_TYPE(__section, __type, __name, __level)		\
+	push_section_type(__section, __type, __name, __level, )
+#  endif
+
+# endif /* LINKER_SCRIPT */
+#else /* defined(__ASSEMBLER__) || defined(__ASSEMBLY__) */
+
+/*
+ * 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
+
+# ifndef section_type
+#  define section_type(__section, __type, __name, __level, __flags)	\
+	__stringify(__section_type(__section, __type, __name,		\
+				   __level, __stringify(__flags)))	\
+	ASM_CMD_SEP
+# endif
+
+/*
+ * Some architectures (arm, and avr32 are two examples on kprobes) seem
+ * currently explicitly specify the asm type [0] -- this can be any of
+ * the optional constants on ELF:
+ *
+ * @progbits - section contains data
+ * @nobits - section does not contain data (i.e., section only occupies space)
+ * @note - section contains data which is used by things other than the program
+ * @init_array - section contains an array of pointers to init functions
+ * @fini_array - section contains an array of pointers to finish functions
+ * @preinit_array - section contains an array of pointers to pre-init functions
+ *
+ * ARM requires % instead of @.
+ *
+ * At least as per nasm (x86/x86_64 only), in the absence of qualifiers the
+ * defaults are as follows:
+ *
+ * section .text    progbits  alloc   exec    nowrite  align=16
+ * section .rodata  progbits  alloc   noexec  nowrite  align=4
+ * section .lrodata progbits  alloc   noexec  nowrite  align=4
+ * section .data    progbits  alloc   noexec  write    align=4
+ * section .ldata   progbits  alloc   noexec  write    align=4
+ * section .bss     nobits    alloc   noexec  write    align=4
+ * section .lbss    nobits    alloc   noexec  write    align=4
+ * section .tdata   progbits  alloc   noexec  write    align=4    tls
+ * section .tbss    nobits    alloc   noexec  write    align=4    tls
+ * section .comment progbits  noalloc noexec  nowrite  align=1
+ * section other    progbits  alloc   noexec  nowrite  align=1
+ *
+ * gas should have sensible defaults for architectures...
+ *
+ * [0] http://www.nasm.us/doc/nasmdoc7.html
+ */
+# ifndef section_type_asmtype
+#  define section_type_asmtype(__section, __type, __name, __level,	\
+			     __flags, __asmtype)			\
+	__stringify(__section_type_asmtype(__section, __type,		\
+					   __name, __level,		\
+					   __stringify(__flags),	\
+					   asmtype))			\
+	ASM_CMD_SEP
+# endif
+
+# ifndef push_section_type
+#  define push_section_type(__section, __type, __name, __level, __flags)	\
+	__stringify(__push_section_type(__section, __type,		\
+					__name,	__level,		\
+					__stringify(__flags)))		\
+	ASM_CMD_SEP
+# endif
+
+#endif /* defined(__ASSEMBLER__) || defined(__ASSEMBLY__) */
+
 #if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
 
 /* References to section boundaries */
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 24563970ff7b..0042f30ff34b 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -55,6 +55,7 @@
 #endif
 
 #include <linux/export.h>
+#include <asm/sections.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
diff --git a/include/linux/sections.h b/include/linux/sections.h
new file mode 100644
index 000000000000..118c46f884a7
--- /dev/null
+++ b/include/linux/sections.h
@@ -0,0 +1,123 @@
+#ifndef _LINUX_SECTIONS_H
+#define _LINUX_SECTIONS_H
+/*
+ * Linux de-facto sections
+ *
+ * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
+ *
+ * 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/.
+ */
+
+#ifdef __KERNEL__
+# include <asm/sections.h>
+#endif /* __KERNEL__ */
+
+#ifndef __ASSEMBLY__
+
+/**
+ * DOC: Linux section helpers
+ *
+ * Set of common helpers which can be used to against custom Linux sections.
+ */
+
+/**
+ * LINUX_SECTION_ALIGNMENT - get section alignment
+ *
+ * @name: section name
+ *
+ * Gives you the alignment for the section.
+ */
+#define LINUX_SECTION_ALIGNMENT(name)	__alignof__(*name)
+
+/**
+ * LINUX_SECTION_SIZE - get number of entries in the section
+ *
+ * @name: section name
+ *
+ * This gives you the number of entries in the section.
+ * Example usage:
+ *
+ *   unsigned int num_frobs = LINUX_SECTION_SIZE(frobnicator_fns);
+ */
+#define LINUX_SECTION_SIZE(name)	((name##__end) - (name))
+
+/**
+ * LINUX_SECTION_EMPTY - check if section has no entries
+ *
+ * @name: section name
+ *
+ * Returns true if section is emtpy.
+ *
+ *   bool is_empty = LINUX_SECTION_EMPTY(frobnicator_fns);
+ */
+#define LINUX_SECTION_EMPTY(name)	(LINUX_SECTION_SIZE(name) == 0)
+
+/**
+ * LINUX_SECTION_START - get address of start of section
+ *
+ * @name: section name
+ *
+ * This gives you the start address of the section.
+ * This should give you the address of the first entry.
+ *
+ */
+#define LINUX_SECTION_START(name)	name
+
+/**
+ * LINUX_SECTION_END - get address of end of the section
+ *
+ * @name: section name
+ *
+ * This gives you the end address of the section.
+ * This should give you the address of the end of the
+ * section. This will match the start address if the
+ * section is empty.
+ */
+#define LINUX_SECTION_END(name)	name##__end
+
+/**
+ * DECLARE_LINUX_SECTION - Declares a custom Linux section
+ *
+ * @type: type of custom Linux section
+ * @name: custom section name
+ *
+ * Declares a read-write custom Linux section
+ */
+#define DECLARE_LINUX_SECTION(type, name)				\
+	 extern type name[], name##__end[];
+
+/**
+ * DECLARE_LINUX_SECTION_RO - Declares a read-only custom Linux section
+ *
+ * @type: type of custom Linux section
+ * @name: custom section name
+ *
+ * Declares a read-only custom Linux section
+ */
+#define DECLARE_LINUX_SECTION_RO(type, name)				\
+	 extern const type name[], name##__end[];
+
+#define __SECTION_TYPE(section, type, name, level)			\
+	#section "." #type "." #name "." #level
+
+/**
+ * SECTION_TYPE - helper to construct a custom section type name
+ *
+ * @section: known de facto section, in asm-generic/sections.h
+ * @type: type of Linux section
+ * @name: custom section name
+ * @level: order level, used to help sort the section entries. The value
+ *	used should be a digit. Since ELF sections are strings there is
+ *	no technical restriction on the length of the number of digits
+ *	used.
+ *
+ * Helper to construct the name of a custom section type.
+ */
+#define SECTION_TYPE(section, type, name, level)                       	\
+	__SECTION_TYPE(section, type, name, level)
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _LINUX_SECTIONS_H */
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 05/13] sections.h: add sections header to collect all section info
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe, Luis R. Rodriguez

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.

We are now generalizing sections.h in code to enable
avoiding modifying the linker when we want to add new
custom Linux sections but to make this generally useful
we need to ensure all architectures also have their own
asm/sections.h, this is now also used by the custom series
of helpers to an architecture's linker script:

  asm-generic/vmlinux.lds.h.

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 Documentation/DocBook/Makefile        |   3 +-
 Documentation/DocBook/sections.tmpl   | 112 +++++++++++++
 arch/alpha/include/asm/sections.h     |   6 +
 arch/arm64/include/asm/sections.h     |   6 +
 arch/avr32/include/asm/sections.h     |   6 +
 arch/cris/include/asm/sections.h      |   6 +
 arch/h8300/include/asm/sections.h     |   6 +
 arch/hexagon/include/asm/sections.h   |   6 +
 arch/m32r/include/asm/sections.h      |   6 +
 arch/m68k/include/asm/sections.h      |   6 +
 arch/metag/include/asm/sections.h     |   6 +
 arch/mips/include/asm/sections.h      |   6 +
 arch/mn10300/include/asm/sections.h   |   6 +
 arch/nios2/include/asm/sections.h     |   6 +
 arch/openrisc/include/asm/sections.h  |   6 +
 arch/score/include/asm/sections.h     |   6 +
 arch/unicore32/include/asm/sections.h |   6 +
 arch/xtensa/include/asm/sections.h    |   6 +
 include/asm-generic/sections.h        | 300 ++++++++++++++++++++++++++++++++++
 include/asm-generic/vmlinux.lds.h     |  27 +--
 include/linux/sections.h              | 123 ++++++++++++++
 21 files changed, 647 insertions(+), 14 deletions(-)
 create mode 100644 Documentation/DocBook/sections.tmpl
 create mode 100644 arch/alpha/include/asm/sections.h
 create mode 100644 arch/arm64/include/asm/sections.h
 create mode 100644 arch/avr32/include/asm/sections.h
 create mode 100644 arch/cris/include/asm/sections.h
 create mode 100644 arch/h8300/include/asm/sections.h
 create mode 100644 arch/hexagon/include/asm/sections.h
 create mode 100644 arch/m32r/include/asm/sections.h
 create mode 100644 arch/m68k/include/asm/sections.h
 create mode 100644 arch/metag/include/asm/sections.h
 create mode 100644 arch/mips/include/asm/sections.h
 create mode 100644 arch/mn10300/include/asm/sections.h
 create mode 100644 arch/nios2/include/asm/sections.h
 create mode 100644 arch/openrisc/include/asm/sections.h
 create mode 100644 arch/score/include/asm/sections.h
 create mode 100644 arch/unicore32/include/asm/sections.h
 create mode 100644 arch/xtensa/include/asm/sections.h
 create mode 100644 include/linux/sections.h

diff --git a/Documentation/DocBook/Makefile b/Documentation/DocBook/Makefile
index 8e6dd4b14314..1b2ac4731418 100644
--- a/Documentation/DocBook/Makefile
+++ b/Documentation/DocBook/Makefile
@@ -17,7 +17,8 @@ DOCBOOKS := z8530book.xml device-drivers.xml \
 	    80211.xml debugobjects.xml sh.xml regulator.xml \
 	    alsa-driver-api.xml writing-an-alsa-driver.xml \
 	    tracepoint.xml media_api.xml w1.xml \
-	    writing_musb_glue_layer.xml crypto-API.xml iio.xml
+	    writing_musb_glue_layer.xml crypto-API.xml iio.xml \
+	    sections.xml
 
 include Documentation/DocBook/media/Makefile
 
diff --git a/Documentation/DocBook/sections.tmpl b/Documentation/DocBook/sections.tmpl
new file mode 100644
index 000000000000..2d14eb20e99c
--- /dev/null
+++ b/Documentation/DocBook/sections.tmpl
@@ -0,0 +1,112 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+	"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
+<set>
+  <setinfo>
+    <title>Linux ELF sections</title>
+    <subtitle>
+      Explains Linux ELF sections
+    </subtitle>
+
+    <copyright>
+      <year>2016</year>
+      <holder>Luis R. Rodriguez</holder>
+    </copyright>
+
+    <authorgroup>
+      <author>
+        <firstname>Luis</firstname>
+        <surname>Rodriguez</surname>
+        <affiliation>
+          <address><email>mcgrof@kernel.org</email></address>
+        </affiliation>
+      </author>
+    </authorgroup>
+
+    <legalnotice>
+      <para>
+        This documentation is free software; you can redistribute
+        it and/or modify it under the terms of the GNU General Public
+        License version 2 as published by the Free Software Foundation.
+      </para>
+      <para>
+        This documentation is distributed in the hope that it will be
+        useful, but WITHOUT ANY WARRANTY; without even the implied
+        warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+        See the GNU General Public License for more details.
+      </para>
+      <para>
+        You should have received a copy of the GNU General Public
+        License along with this documentation; if not, write to the Free
+        Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+        MA 02111-1307 USA
+      </para>
+      <para>
+        For more details see the file COPYING in the source
+        distribution of Linux.
+      </para>
+    </legalnotice>
+
+    <abstract>
+      <para>
+        This book documents the different custom ELF sections used on the Linux
+	kernel and defined on Linux's custom linker script.
+      </para>
+    </abstract>
+  </setinfo>
+  <book id="linux-elf-sections">
+    <bookinfo>
+      <title>Linux kernel ELF sections</title>
+
+      <abstract>
+!Pinclude/asm-generic/sections.h Introduction
+      </abstract>
+    </bookinfo>
+
+      <chapter>
+      <title>Linux kernel sections helpers</title>
+!Pinclude/linux/sections.h Linux section helpers
+!Finclude/linux/sections.h LINUX_SECTION_ALIGNMENT
+!Finclude/linux/sections.h LINUX_SECTION_SIZE
+!Finclude/linux/sections.h LINUX_SECTION_EMPTY
+!Finclude/linux/sections.h LINUX_SECTION_START
+!Finclude/linux/sections.h LINUX_SECTION_END
+!Finclude/linux/sections.h DECLARE_LINUX_SECTION
+!Finclude/linux/sections.h DECLARE_LINUX_SECTION_RO
+!Finclude/linux/sections.h SECTION_TYPE
+      </chapter>
+
+      <chapter>
+      <title>Core Linux kernel sections</title>
+!Pinclude/asm-generic/sections.h Core Linux kernel sections
+!Finclude/asm-generic/sections.h SECTION_RODATA
+!Finclude/asm-generic/sections.h SECTION_TEXT
+!Finclude/asm-generic/sections.h SECTION_DATA
+      </chapter>
+
+      <chapter>
+      <title>Linux .init* sections</title>
+!Pinclude/asm-generic/sections.h Linux init sections
+!Finclude/asm-generic/sections.h SECTION_INIT_DATA
+!Finclude/asm-generic/sections.h SECTION_INIT_RODATA
+!Finclude/asm-generic/sections.h SECTION_INIT_CALL
+      </chapter>
+
+      <chapter>
+      <title>Linux .exit* sections</title>
+!Pinclude/asm-generic/sections.h Linux exit sections
+!Finclude/asm-generic/sections.h SECTION_EXIT
+!Finclude/asm-generic/sections.h SECTION_EXIT_DATA
+!Finclude/asm-generic/sections.h SECTION_EXIT_CALL
+      </chapter>
+
+      <chapter>
+      <title>Linux .ref* sections</title>
+!Pinclude/asm-generic/sections.h Linux references to init sections
+!Finclude/asm-generic/sections.h SECTION_REF
+!Finclude/asm-generic/sections.h SECTION_REF_DATA
+!Finclude/asm-generic/sections.h SECTION_REF_RODATA
+      </chapter>
+
+  </book>
+</set>
diff --git a/arch/alpha/include/asm/sections.h b/arch/alpha/include/asm/sections.h
new file mode 100644
index 000000000000..e58fc679fe15
--- /dev/null
+++ b/arch/alpha/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ALPHA_SECTIONS_H
+#define _ASM_ALPHA_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_ALPHA_SECTIONS_H */
diff --git a/arch/arm64/include/asm/sections.h b/arch/arm64/include/asm/sections.h
new file mode 100644
index 000000000000..cd20ecc157a0
--- /dev/null
+++ b/arch/arm64/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARM64_SECTIONS_H
+#define _ASM_ARM64_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_ARM64_SECTIONS_H */
diff --git a/arch/avr32/include/asm/sections.h b/arch/avr32/include/asm/sections.h
new file mode 100644
index 000000000000..78b3ded34489
--- /dev/null
+++ b/arch/avr32/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_AVR32_SECTIONS_H
+#define _ASM_AVR32_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_AVR32_SECTIONS_H */
diff --git a/arch/cris/include/asm/sections.h b/arch/cris/include/asm/sections.h
new file mode 100644
index 000000000000..802a2433780b
--- /dev/null
+++ b/arch/cris/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_CRIS_SECTIONS_H
+#define _ASM_CRIS_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_CRIS_SECTIONS_H */
diff --git a/arch/h8300/include/asm/sections.h b/arch/h8300/include/asm/sections.h
new file mode 100644
index 000000000000..85ba9501a276
--- /dev/null
+++ b/arch/h8300/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_H8300_SECTIONS_H
+#define _ASM_H8300_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_H8300_SECTIONS_H */
diff --git a/arch/hexagon/include/asm/sections.h b/arch/hexagon/include/asm/sections.h
new file mode 100644
index 000000000000..f905cf754efd
--- /dev/null
+++ b/arch/hexagon/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_HEXAGON_SECTIONS_H
+#define _ASM_HEXAGON_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_HEXAGON_SECTIONS_H */
diff --git a/arch/m32r/include/asm/sections.h b/arch/m32r/include/asm/sections.h
new file mode 100644
index 000000000000..25cfc2068443
--- /dev/null
+++ b/arch/m32r/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_M32R_SECTIONS_H
+#define _ASM_M32R_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_M32R_SECTIONS_H */
diff --git a/arch/m68k/include/asm/sections.h b/arch/m68k/include/asm/sections.h
new file mode 100644
index 000000000000..d64967ecfec6
--- /dev/null
+++ b/arch/m68k/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_M68K_SECTIONS_H
+#define _ASM_M68K_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_M68K_SECTIONS_H */
diff --git a/arch/metag/include/asm/sections.h b/arch/metag/include/asm/sections.h
new file mode 100644
index 000000000000..bb76d9a1ec20
--- /dev/null
+++ b/arch/metag/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_METAG_SECTIONS_H
+#define _ASM_METAG_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_METAG_SECTIONS_H */
diff --git a/arch/mips/include/asm/sections.h b/arch/mips/include/asm/sections.h
new file mode 100644
index 000000000000..425b508acfc7
--- /dev/null
+++ b/arch/mips/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MIPS_SECTIONS_H
+#define _ASM_MIPS_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_MIPS_SECTIONS_H */
diff --git a/arch/mn10300/include/asm/sections.h b/arch/mn10300/include/asm/sections.h
new file mode 100644
index 000000000000..61a62637a860
--- /dev/null
+++ b/arch/mn10300/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MN10300_SECTIONS_H
+#define _ASM_MN10300_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_MN10300_SECTIONS_H */
diff --git a/arch/nios2/include/asm/sections.h b/arch/nios2/include/asm/sections.h
new file mode 100644
index 000000000000..b6fc5d8e2e77
--- /dev/null
+++ b/arch/nios2/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_NIOS2_SECTIONS_H
+#define _ASM_NIOS2_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_NIOS2_SECTIONS_H */
diff --git a/arch/openrisc/include/asm/sections.h b/arch/openrisc/include/asm/sections.h
new file mode 100644
index 000000000000..561ee5ac5ead
--- /dev/null
+++ b/arch/openrisc/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_OPENRISC_SECTIONS_H
+#define _ASM_OPENRISC_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_OPENRISC_SECTIONS_H */
diff --git a/arch/score/include/asm/sections.h b/arch/score/include/asm/sections.h
new file mode 100644
index 000000000000..9441d23af005
--- /dev/null
+++ b/arch/score/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SCORE_SECTIONS_H
+#define _ASM_SCORE_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_SCORE_SECTIONS_H */
diff --git a/arch/unicore32/include/asm/sections.h b/arch/unicore32/include/asm/sections.h
new file mode 100644
index 000000000000..ec4cd27c85be
--- /dev/null
+++ b/arch/unicore32/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_UNICORE32_SECTIONS_H
+#define _ASM_UNICORE32_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_UNICORE32_SECTIONS_H */
diff --git a/arch/xtensa/include/asm/sections.h b/arch/xtensa/include/asm/sections.h
new file mode 100644
index 000000000000..ab1176a674c9
--- /dev/null
+++ b/arch/xtensa/include/asm/sections.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_XTENSA_SECTIONS_H
+#define _ASM_XTENSA_SECTIONS_H
+
+#include <asm-generic/sections.h>
+
+#endif /* _ASM_XTENSA_SECTIONS_H */
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index efd51e70a8db..cd4313c3edf8 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -1,6 +1,306 @@
 #ifndef _ASM_GENERIC_SECTIONS_H_
 #define _ASM_GENERIC_SECTIONS_H_
 
+/**
+ * DOC: Introduction
+ *
+ * The Linux vmlinux binary uses a custom linker script which adds
+ * some custom specialized ELF sections. This aims to document those
+ * sections. Each section must document the goal of the section, and
+ * address concurrency considerations when applicable.
+ */
+
+/**
+ * DOC: Core Linux kernel sections
+ *
+ * These are the core Linux kernel sections.
+ */
+
+/**
+ * SECTION_RODATA - read only data
+ *
+ * Macro name for code which must be protected from write access.
+ */
+#define SECTION_RODATA			.rodata
+
+/**
+ * SECTION_TEXT - kernel code execution section, read-only
+ *
+ * Macro name used to annotate code (functions) used during regular
+ * kernel run time. This is combined with SECTION_RODATA, only this
+ * section also gets execution allowed.
+ *
+ */
+#define SECTION_TEXT			.text
+
+/**
+ * SECTION_DATA - for read-write data
+ *
+ * Macro name for read-write data.
+ */
+#define SECTION_DATA			.data
+
+/**
+ * DOC: Linux init sections
+ *
+ * These sections are used for code and data structures used during boot or
+ * module initialization. On architectures that support it (x86, x86_64), all
+ * this code is freed up by the kernel right before the fist userspace init
+ * process is called when built-in to the kernel, and if modular it is freed
+ * after module initialization. Since the code is freed so early, in theory
+ * there should be no races against freeing this code with other CPUs. Init
+ * section code and data structures should never be exported with
+ * EXPORT_SYMBOL*() as the code will quickly become unavailable to the kernel
+ * after bootup.
+ */
+
+/**
+ * SECTION_INIT - boot initialization code
+ *
+ * Macro name used to annotate code (functions) used only during boot or driver
+ * initialization.
+ *
+ */
+#define SECTION_INIT			.init.text
+
+/**
+ * SECTION_INIT_DATA - boot initialization data
+ *
+ * Macro name used to annotate data structures used only during boot or driver
+ * initialization.
+ */
+#define SECTION_INIT_DATA		.init.data
+
+/**
+ * SECTION_INIT_RODATA - boot read-only initialization data
+ *
+ * Macro name used to annotate read-only code (functions) used only during boot
+ * or driver initialization.
+ */
+#define SECTION_INIT_RODATA		.init.rodata
+
+/**
+ * SECTION_INIT_CALL - special init call
+ *
+ * Special macro name used to annotate subsystem init call. These calls are
+ * are now grouped by functionality into separate subsections. Ordering inside
+ * the subsections is determined by link order.
+ */
+#define SECTION_INIT_CALL		.initcall
+
+/**
+ * DOC: Linux exit sections
+ *
+ * These sections are used to declare a functions and data structures which
+ * are only required on exit, the function or data structure will be dropped
+ * if the code declaring this section is not compiled as a module on
+ * architectures that support this (x86, x86_64). There is no special case
+ * handling for this code when built-in to the kernel.
+ */
+
+/**
+ * SECTION_EXIT - module exit code
+ *
+ * Macro name used to annotate code (functions) used only during module
+ * unload.
+ */
+#define SECTION_EXIT			.exit.text
+
+/**
+ * SECTION_EXIT_DATA - module exit data structures
+ *
+ * Macro name used to annotate data structures used only during module
+ * unload.
+ */
+#define SECTION_EXIT_DATA		.exit.data
+
+/**
+ * SECTION_EXIT_CALL - special exit call
+ *
+ * Special macro name used to annotate an exit exit routine, order
+ * is important and maintained by link order.
+ */
+#define SECTION_EXIT_CALL		.exitcall.exit
+
+/**
+ * DOC: Linux references to init sections
+ *
+ * These sections are used to teach modpost to not warn about possible
+ * misuses of init section code from other sections. If you use this
+ * your use case should document why you are certain such use of init
+ * sectioned code is valid. For more details refer to include/linux/init.h
+ * __ref, __refdata, and __refconst documentation.
+ */
+
+/**
+ * SECTION_REF - code referencing init is valid
+ *
+ * Macro name used to annotate that code (functions) declared with this section
+ * has been vetteed as valid for its reference or use of other code (functions)
+ * or data structures which are part of the init sections.
+ */
+#define SECTION_REF			.ref.text
+
+/**
+ * SECTION_REF_DATA - reference data structure are valid
+ *
+ * Macro name used to annotate data structures declared with this section have
+ * been vetteed for its reference or use of other code (functions) or data
+ * structures part of the init sections.
+ */
+#define SECTION_REF_DATA		.ref.data
+
+/**
+ * SECTION_REF_RODATA - const code or data structure referencing init is valid
+ *
+ * Macro name used to annotate const code (functions) const data structures
+ * which has been vetteed for its reference or use of other code (functions)
+ * or data structures part of the init sections.
+ */
+#define SECTION_REF_RODATA		.ref.rodata
+
+#define SECTION_ORDER_ANY	any
+
+/*
+ * These section _ALL() helpers are for use on linker scripts and helpers
+ */
+#define SECTION_ALL(__section)						\
+	__section##.*
+#define SECTION_TYPE_ALL(__section, __type)				\
+	__section##.##__type##.*
+
+/* Can be used on foo.S for instance */
+#ifndef __section_type_asmtype
+# define __section_type_asmtype(__section, __type, __name,		\
+			        __level, __flags, __asm_type)		\
+	.section __section.__type.__name.__level, __flags, __asm_type
+#endif
+
+#ifndef __section_type
+# define __section_type(__section, __type, __name, __level, __flags)	\
+	.section __section.__type.__name.__level, __flags
+#endif
+
+#ifndef __push_section_type
+# define __push_section_type(__section, __type, __name, __level, __flags) \
+	.pushsection __section.__type.__name.__level, __flags
+#endif
+
+#ifdef __KERNEL__
+#include <linux/stringify.h>
+#endif
+
+#if defined(__ASSEMBLER__) || defined(__ASSEMBLY__)
+
+# ifdef LINKER_SCRIPT
+
+#  ifndef SECTION_TYPE
+#   define SECTION_TYPE(__section, __type, __name, __level)		\
+	__section.__type.__name.__level
+#  endif
+
+# else
+
+#  ifndef push_section_type
+#   define push_section_type(__section, __type, __name, __level, __flags) \
+	 __push_section_type(__section, __type, __name,			  \
+			     __level, __stringify(__flags))
+#  endif
+
+#  ifndef section_type
+#   define section_type(__section, __type, __name, __level, __flags)	\
+	__section_type(__section, __type, __name,			\
+		       __level, __stringify(__flags))
+#  endif
+
+#  ifndef section_type_asmtype
+#   define section_type_asmtype(__section, __type, __name,		\
+			        __level, __flags, __asmtype)		\
+	__section_type_asmtype(__section, __type, __name, __level,	\
+			       __stringify(__flags), __asmtype)
+#  endif
+
+#  ifndef SECTION_TYPE
+#   define SECTION_TYPE(__section, __type, __name, __level)		\
+	push_section_type(__section, __type, __name, __level, )
+#  endif
+
+# endif /* LINKER_SCRIPT */
+#else /* defined(__ASSEMBLER__) || defined(__ASSEMBLY__) */
+
+/*
+ * 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
+
+# ifndef section_type
+#  define section_type(__section, __type, __name, __level, __flags)	\
+	__stringify(__section_type(__section, __type, __name,		\
+				   __level, __stringify(__flags)))	\
+	ASM_CMD_SEP
+# endif
+
+/*
+ * Some architectures (arm, and avr32 are two examples on kprobes) seem
+ * currently explicitly specify the asm type [0] -- this can be any of
+ * the optional constants on ELF:
+ *
+ * @progbits - section contains data
+ * @nobits - section does not contain data (i.e., section only occupies space)
+ * @note - section contains data which is used by things other than the program
+ * @init_array - section contains an array of pointers to init functions
+ * @fini_array - section contains an array of pointers to finish functions
+ * @preinit_array - section contains an array of pointers to pre-init functions
+ *
+ * ARM requires % instead of @.
+ *
+ * At least as per nasm (x86/x86_64 only), in the absence of qualifiers the
+ * defaults are as follows:
+ *
+ * section .text    progbits  alloc   exec    nowrite  align=16
+ * section .rodata  progbits  alloc   noexec  nowrite  align=4
+ * section .lrodata progbits  alloc   noexec  nowrite  align=4
+ * section .data    progbits  alloc   noexec  write    align=4
+ * section .ldata   progbits  alloc   noexec  write    align=4
+ * section .bss     nobits    alloc   noexec  write    align=4
+ * section .lbss    nobits    alloc   noexec  write    align=4
+ * section .tdata   progbits  alloc   noexec  write    align=4    tls
+ * section .tbss    nobits    alloc   noexec  write    align=4    tls
+ * section .comment progbits  noalloc noexec  nowrite  align=1
+ * section other    progbits  alloc   noexec  nowrite  align=1
+ *
+ * gas should have sensible defaults for architectures...
+ *
+ * [0] http://www.nasm.us/doc/nasmdoc7.html
+ */
+# ifndef section_type_asmtype
+#  define section_type_asmtype(__section, __type, __name, __level,	\
+			     __flags, __asmtype)			\
+	__stringify(__section_type_asmtype(__section, __type,		\
+					   __name, __level,		\
+					   __stringify(__flags),	\
+					   asmtype))			\
+	ASM_CMD_SEP
+# endif
+
+# ifndef push_section_type
+#  define push_section_type(__section, __type, __name, __level, __flags)	\
+	__stringify(__push_section_type(__section, __type,		\
+					__name,	__level,		\
+					__stringify(__flags)))		\
+	ASM_CMD_SEP
+# endif
+
+#endif /* defined(__ASSEMBLER__) || defined(__ASSEMBLY__) */
+
 #if defined(__KERNEL__) && !defined(__ASSEMBLER__) && !defined(__ASSEMBLY__)
 
 /* References to section boundaries */
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 24563970ff7b..0042f30ff34b 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -55,6 +55,7 @@
 #endif
 
 #include <linux/export.h>
+#include <asm/sections.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
diff --git a/include/linux/sections.h b/include/linux/sections.h
new file mode 100644
index 000000000000..118c46f884a7
--- /dev/null
+++ b/include/linux/sections.h
@@ -0,0 +1,123 @@
+#ifndef _LINUX_SECTIONS_H
+#define _LINUX_SECTIONS_H
+/*
+ * Linux de-facto sections
+ *
+ * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
+ *
+ * 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/.
+ */
+
+#ifdef __KERNEL__
+# include <asm/sections.h>
+#endif /* __KERNEL__ */
+
+#ifndef __ASSEMBLY__
+
+/**
+ * DOC: Linux section helpers
+ *
+ * Set of common helpers which can be used to against custom Linux sections.
+ */
+
+/**
+ * LINUX_SECTION_ALIGNMENT - get section alignment
+ *
+ * @name: section name
+ *
+ * Gives you the alignment for the section.
+ */
+#define LINUX_SECTION_ALIGNMENT(name)	__alignof__(*name)
+
+/**
+ * LINUX_SECTION_SIZE - get number of entries in the section
+ *
+ * @name: section name
+ *
+ * This gives you the number of entries in the section.
+ * Example usage:
+ *
+ *   unsigned int num_frobs = LINUX_SECTION_SIZE(frobnicator_fns);
+ */
+#define LINUX_SECTION_SIZE(name)	((name##__end) - (name))
+
+/**
+ * LINUX_SECTION_EMPTY - check if section has no entries
+ *
+ * @name: section name
+ *
+ * Returns true if section is emtpy.
+ *
+ *   bool is_empty = LINUX_SECTION_EMPTY(frobnicator_fns);
+ */
+#define LINUX_SECTION_EMPTY(name)	(LINUX_SECTION_SIZE(name) == 0)
+
+/**
+ * LINUX_SECTION_START - get address of start of section
+ *
+ * @name: section name
+ *
+ * This gives you the start address of the section.
+ * This should give you the address of the first entry.
+ *
+ */
+#define LINUX_SECTION_START(name)	name
+
+/**
+ * LINUX_SECTION_END - get address of end of the section
+ *
+ * @name: section name
+ *
+ * This gives you the end address of the section.
+ * This should give you the address of the end of the
+ * section. This will match the start address if the
+ * section is empty.
+ */
+#define LINUX_SECTION_END(name)	name##__end
+
+/**
+ * DECLARE_LINUX_SECTION - Declares a custom Linux section
+ *
+ * @type: type of custom Linux section
+ * @name: custom section name
+ *
+ * Declares a read-write custom Linux section
+ */
+#define DECLARE_LINUX_SECTION(type, name)				\
+	 extern type name[], name##__end[];
+
+/**
+ * DECLARE_LINUX_SECTION_RO - Declares a read-only custom Linux section
+ *
+ * @type: type of custom Linux section
+ * @name: custom section name
+ *
+ * Declares a read-only custom Linux section
+ */
+#define DECLARE_LINUX_SECTION_RO(type, name)				\
+	 extern const type name[], name##__end[];
+
+#define __SECTION_TYPE(section, type, name, level)			\
+	#section "." #type "." #name "." #level
+
+/**
+ * SECTION_TYPE - helper to construct a custom section type name
+ *
+ * @section: known de facto section, in asm-generic/sections.h
+ * @type: type of Linux section
+ * @name: custom section name
+ * @level: order level, used to help sort the section entries. The value
+ *	used should be a digit. Since ELF sections are strings there is
+ *	no technical restriction on the length of the number of digits
+ *	used.
+ *
+ * Helper to construct the name of a custom section type.
+ */
+#define SECTION_TYPE(section, type, name, level)                       	\
+	__SECTION_TYPE(section, type, name, level)
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _LINUX_SECTIONS_H */
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 06/13] ranges.h: add helpers to build and identify Linux section ranges
  2016-07-22 21:24 ` Luis R. Rodriguez
  (?)
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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 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 defult trusting the asm-generic
version all around.

v3: new in this series, uses copyleft-next

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 arch/alpha/include/asm/ranges.h      |  6 ++++
 arch/arc/include/asm/ranges.h        |  6 ++++
 arch/arm/include/asm/ranges.h        |  6 ++++
 arch/arm64/include/asm/ranges.h      |  6 ++++
 arch/avr32/include/asm/ranges.h      |  6 ++++
 arch/blackfin/include/asm/ranges.h   |  6 ++++
 arch/c6x/include/asm/ranges.h        |  6 ++++
 arch/cris/include/asm/ranges.h       |  6 ++++
 arch/frv/include/asm/ranges.h        |  6 ++++
 arch/h8300/include/asm/ranges.h      |  6 ++++
 arch/hexagon/include/asm/ranges.h    |  6 ++++
 arch/ia64/include/asm/ranges.h       |  6 ++++
 arch/m32r/include/asm/ranges.h       |  6 ++++
 arch/m68k/include/asm/ranges.h       |  6 ++++
 arch/metag/include/asm/ranges.h      |  6 ++++
 arch/microblaze/include/asm/ranges.h |  6 ++++
 arch/mips/include/asm/ranges.h       |  6 ++++
 arch/mn10300/include/asm/ranges.h    |  6 ++++
 arch/nios2/include/asm/ranges.h      |  6 ++++
 arch/openrisc/include/asm/ranges.h   |  6 ++++
 arch/parisc/include/asm/ranges.h     |  6 ++++
 arch/powerpc/include/asm/ranges.h    |  6 ++++
 arch/s390/include/asm/ranges.h       |  6 ++++
 arch/score/include/asm/ranges.h      |  6 ++++
 arch/sh/include/asm/ranges.h         |  6 ++++
 arch/sparc/include/asm/ranges.h      |  6 ++++
 arch/tile/include/asm/ranges.h       |  6 ++++
 arch/um/include/asm/ranges.h         |  6 ++++
 arch/unicore32/include/asm/ranges.h  |  6 ++++
 arch/x86/include/asm/ranges.h        |  6 ++++
 arch/xtensa/include/asm/ranges.h     |  6 ++++
 include/asm-generic/ranges.h         | 70 ++++++++++++++++++++++++++++++++++++
 include/linux/ranges.h               | 54 ++++++++++++++++++++++++++++
 33 files changed, 310 insertions(+)
 create mode 100644 arch/alpha/include/asm/ranges.h
 create mode 100644 arch/arc/include/asm/ranges.h
 create mode 100644 arch/arm/include/asm/ranges.h
 create mode 100644 arch/arm64/include/asm/ranges.h
 create mode 100644 arch/avr32/include/asm/ranges.h
 create mode 100644 arch/blackfin/include/asm/ranges.h
 create mode 100644 arch/c6x/include/asm/ranges.h
 create mode 100644 arch/cris/include/asm/ranges.h
 create mode 100644 arch/frv/include/asm/ranges.h
 create mode 100644 arch/h8300/include/asm/ranges.h
 create mode 100644 arch/hexagon/include/asm/ranges.h
 create mode 100644 arch/ia64/include/asm/ranges.h
 create mode 100644 arch/m32r/include/asm/ranges.h
 create mode 100644 arch/m68k/include/asm/ranges.h
 create mode 100644 arch/metag/include/asm/ranges.h
 create mode 100644 arch/microblaze/include/asm/ranges.h
 create mode 100644 arch/mips/include/asm/ranges.h
 create mode 100644 arch/mn10300/include/asm/ranges.h
 create mode 100644 arch/nios2/include/asm/ranges.h
 create mode 100644 arch/openrisc/include/asm/ranges.h
 create mode 100644 arch/parisc/include/asm/ranges.h
 create mode 100644 arch/powerpc/include/asm/ranges.h
 create mode 100644 arch/s390/include/asm/ranges.h
 create mode 100644 arch/score/include/asm/ranges.h
 create mode 100644 arch/sh/include/asm/ranges.h
 create mode 100644 arch/sparc/include/asm/ranges.h
 create mode 100644 arch/tile/include/asm/ranges.h
 create mode 100644 arch/um/include/asm/ranges.h
 create mode 100644 arch/unicore32/include/asm/ranges.h
 create mode 100644 arch/x86/include/asm/ranges.h
 create mode 100644 arch/xtensa/include/asm/ranges.h
 create mode 100644 include/asm-generic/ranges.h
 create mode 100644 include/linux/ranges.h

diff --git a/arch/alpha/include/asm/ranges.h b/arch/alpha/include/asm/ranges.h
new file mode 100644
index 000000000000..b7bc4107bc75
--- /dev/null
+++ b/arch/alpha/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ALPHA_RANGES_H
+#define _ASM_ALPHA_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_ALPHA_RANGES_H */
diff --git a/arch/arc/include/asm/ranges.h b/arch/arc/include/asm/ranges.h
new file mode 100644
index 000000000000..a761243bf79f
--- /dev/null
+++ b/arch/arc/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARC_RANGES_H
+#define _ASM_ARC_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_ARC_RANGES_H */
diff --git a/arch/arm/include/asm/ranges.h b/arch/arm/include/asm/ranges.h
new file mode 100644
index 000000000000..fb059e205f90
--- /dev/null
+++ b/arch/arm/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARM_RANGES_H
+#define _ASM_ARM_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_ARM_RANGES_H */
diff --git a/arch/arm64/include/asm/ranges.h b/arch/arm64/include/asm/ranges.h
new file mode 100644
index 000000000000..0e0b52cc8d41
--- /dev/null
+++ b/arch/arm64/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARM64_RANGES_H
+#define _ASM_ARM64_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_ARM64_RANGES_H */
diff --git a/arch/avr32/include/asm/ranges.h b/arch/avr32/include/asm/ranges.h
new file mode 100644
index 000000000000..0f50a1af03e1
--- /dev/null
+++ b/arch/avr32/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_AVR32_RANGES_H
+#define _ASM_AVR32_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_AVR32_RANGES_H */
diff --git a/arch/blackfin/include/asm/ranges.h b/arch/blackfin/include/asm/ranges.h
new file mode 100644
index 000000000000..e1d133639a45
--- /dev/null
+++ b/arch/blackfin/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_BLACKFIN_RANGES_H
+#define _ASM_BLACKFIN_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_BLACKFIN_RANGES_H */
diff --git a/arch/c6x/include/asm/ranges.h b/arch/c6x/include/asm/ranges.h
new file mode 100644
index 000000000000..0e8e6e149d55
--- /dev/null
+++ b/arch/c6x/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_C6X_RANGES_H
+#define _ASM_C6X_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_C6X_RANGES_H */
diff --git a/arch/cris/include/asm/ranges.h b/arch/cris/include/asm/ranges.h
new file mode 100644
index 000000000000..8567f55ae4ea
--- /dev/null
+++ b/arch/cris/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_CRIS_RANGES_H
+#define _ASM_CRIS_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_CRIS_RANGES_H */
diff --git a/arch/frv/include/asm/ranges.h b/arch/frv/include/asm/ranges.h
new file mode 100644
index 000000000000..f11a6f0fb0bd
--- /dev/null
+++ b/arch/frv/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_FRV_RANGES_H
+#define _ASM_FRV_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_FRV_RANGES_H */
diff --git a/arch/h8300/include/asm/ranges.h b/arch/h8300/include/asm/ranges.h
new file mode 100644
index 000000000000..ab08bd6bd067
--- /dev/null
+++ b/arch/h8300/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_H8300_RANGES_H
+#define _ASM_H8300_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_H8300_RANGES_H */
diff --git a/arch/hexagon/include/asm/ranges.h b/arch/hexagon/include/asm/ranges.h
new file mode 100644
index 000000000000..56e5241abc6b
--- /dev/null
+++ b/arch/hexagon/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_HEXAGON_RANGES_H
+#define _ASM_HEXAGON_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_HEXAGON_RANGES_H */
diff --git a/arch/ia64/include/asm/ranges.h b/arch/ia64/include/asm/ranges.h
new file mode 100644
index 000000000000..4e69cbcfd0e7
--- /dev/null
+++ b/arch/ia64/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_IA64_RANGES_H
+#define _ASM_IA64_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_IA64_RANGES_H */
diff --git a/arch/m32r/include/asm/ranges.h b/arch/m32r/include/asm/ranges.h
new file mode 100644
index 000000000000..dd33a0b94de4
--- /dev/null
+++ b/arch/m32r/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_M32R_RANGES_H
+#define _ASM_M32R_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_M32R_RANGES_H */
diff --git a/arch/m68k/include/asm/ranges.h b/arch/m68k/include/asm/ranges.h
new file mode 100644
index 000000000000..292a00baa73e
--- /dev/null
+++ b/arch/m68k/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_M68K_RANGES_H
+#define _ASM_M68K_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_M68K_RANGES_H */
diff --git a/arch/metag/include/asm/ranges.h b/arch/metag/include/asm/ranges.h
new file mode 100644
index 000000000000..42a77c098c85
--- /dev/null
+++ b/arch/metag/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_METAG_RANGES_H
+#define _ASM_METAG_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_METAG_RANGES_H */
diff --git a/arch/microblaze/include/asm/ranges.h b/arch/microblaze/include/asm/ranges.h
new file mode 100644
index 000000000000..48d58e38f1e1
--- /dev/null
+++ b/arch/microblaze/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MICROBLAZE_RANGES_H
+#define _ASM_MICROBLAZE_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_MICROBLAZE_RANGES_H */
diff --git a/arch/mips/include/asm/ranges.h b/arch/mips/include/asm/ranges.h
new file mode 100644
index 000000000000..675a55cd3719
--- /dev/null
+++ b/arch/mips/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MIPS_RANGES_H
+#define _ASM_MIPS_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_MIPS_RANGES_H */
diff --git a/arch/mn10300/include/asm/ranges.h b/arch/mn10300/include/asm/ranges.h
new file mode 100644
index 000000000000..fb7f43a3c19d
--- /dev/null
+++ b/arch/mn10300/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MN10300_RANGES_H
+#define _ASM_MN10300_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_MN10300_RANGES_H */
diff --git a/arch/nios2/include/asm/ranges.h b/arch/nios2/include/asm/ranges.h
new file mode 100644
index 000000000000..ab1991981c0f
--- /dev/null
+++ b/arch/nios2/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_NIOS2_RANGES_H
+#define _ASM_NIOS2_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_NIOS2_RANGES_H */
diff --git a/arch/openrisc/include/asm/ranges.h b/arch/openrisc/include/asm/ranges.h
new file mode 100644
index 000000000000..a64be842983f
--- /dev/null
+++ b/arch/openrisc/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_OPENRISC_RANGES_H
+#define _ASM_OPENRISC_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_OPENRISC_RANGES_H */
diff --git a/arch/parisc/include/asm/ranges.h b/arch/parisc/include/asm/ranges.h
new file mode 100644
index 000000000000..dd6b5c215941
--- /dev/null
+++ b/arch/parisc/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_PARISC_RANGES_H
+#define _ASM_PARISC_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_PARISC_RANGES_H */
diff --git a/arch/powerpc/include/asm/ranges.h b/arch/powerpc/include/asm/ranges.h
new file mode 100644
index 000000000000..240c51a210d4
--- /dev/null
+++ b/arch/powerpc/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_POWERPC_RANGES_H
+#define _ASM_POWERPC_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_POWERPC_RANGES_H */
diff --git a/arch/s390/include/asm/ranges.h b/arch/s390/include/asm/ranges.h
new file mode 100644
index 000000000000..d4788451f176
--- /dev/null
+++ b/arch/s390/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_S390_RANGES_H
+#define _ASM_S390_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_S390_RANGES_H */
diff --git a/arch/score/include/asm/ranges.h b/arch/score/include/asm/ranges.h
new file mode 100644
index 000000000000..d67f859eeda3
--- /dev/null
+++ b/arch/score/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SCORE_RANGES_H
+#define _ASM_SCORE_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_SCORE_RANGES_H */
diff --git a/arch/sh/include/asm/ranges.h b/arch/sh/include/asm/ranges.h
new file mode 100644
index 000000000000..99df0b65f40a
--- /dev/null
+++ b/arch/sh/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SH_RANGES_H
+#define _ASM_SH_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_SH_RANGES_H */
diff --git a/arch/sparc/include/asm/ranges.h b/arch/sparc/include/asm/ranges.h
new file mode 100644
index 000000000000..8ff4765ccd9b
--- /dev/null
+++ b/arch/sparc/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SPARC_RANGES_H
+#define _ASM_SPARC_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_SPARC_RANGES_H */
diff --git a/arch/tile/include/asm/ranges.h b/arch/tile/include/asm/ranges.h
new file mode 100644
index 000000000000..ceda3fb075e0
--- /dev/null
+++ b/arch/tile/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_TILE_RANGES_H
+#define _ASM_TILE_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_TILE_RANGES_H */
diff --git a/arch/um/include/asm/ranges.h b/arch/um/include/asm/ranges.h
new file mode 100644
index 000000000000..7c9c20e47879
--- /dev/null
+++ b/arch/um/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_UM_RANGES_H
+#define _ASM_UM_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_UM_RANGES_H */
diff --git a/arch/unicore32/include/asm/ranges.h b/arch/unicore32/include/asm/ranges.h
new file mode 100644
index 000000000000..92526340d73c
--- /dev/null
+++ b/arch/unicore32/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_UNICORE32_RANGES_H
+#define _ASM_UNICORE32_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_UNICORE32_RANGES_H */
diff --git a/arch/x86/include/asm/ranges.h b/arch/x86/include/asm/ranges.h
new file mode 100644
index 000000000000..4a0c824d4082
--- /dev/null
+++ b/arch/x86/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_X86_RANGES_H
+#define _ASM_X86_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_X86_RANGES_H */
diff --git a/arch/xtensa/include/asm/ranges.h b/arch/xtensa/include/asm/ranges.h
new file mode 100644
index 000000000000..c7360d1c9c85
--- /dev/null
+++ b/arch/xtensa/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_XTENSA_RANGES_H
+#define _ASM_XTENSA_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_XTENSA_RANGES_H */
diff --git a/include/asm-generic/ranges.h b/include/asm-generic/ranges.h
new file mode 100644
index 000000000000..0d54c632f714
--- /dev/null
+++ b/include/asm-generic/ranges.h
@@ -0,0 +1,70 @@
+#ifndef _ASM_GENERIC_RANGES_H_
+#define _ASM_GENERIC_RANGES_H_
+/*
+ * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
+ *
+ * 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/.
+ */
+#ifdef __KERNEL__
+# include <asm/sections.h>
+#endif /* __KERNEL__ */
+
+#define SECTION_TYPE_RANGES	rng
+
+#define SECTION_RNG(section, name)					\
+	SECTION_TYPE(section, SECTION_TYPE_RANGES, name,		\
+		     SECTION_ORDER_ANY)
+
+#define SECTION_RNG_LEVEL(section, name, level)				\
+	SECTION_TYPE(section, SECTION_TYPE_RANGES, name, level)
+
+#define SECTION_RANGE_ALL(section)					\
+	SECTION_TYPE_ALL(section,SECTION_TYPE_RANGES)
+
+#ifndef section_rng
+# define section_rng(section, name, flags)				\
+	 section_type(section, SECTION_TYPE_RANGES, name,		\
+		      SECTION_ORDER_ANY, flags)
+#endif
+
+#ifndef section_rng_asmtype
+# define section_rng_asmtype(section, name, flags, asmtype)		\
+	 section_type_asmtype(section, SECTION_TYPE_RANGES, name,	\
+			      SECTION_ORDER_ANY, flags, asmtype)
+#endif
+
+#ifndef section_rng_level
+# define section_rng_level(section, name, level, flags)			\
+	 section_type(section, SECTION_TYPE_RANGES, name, level, flags)
+#endif
+
+#ifndef push_section_rng
+# define push_section_rng(section, name, flags)				\
+	 push_section_type(section, SECTION_TYPE_RANGES, name,		\
+			  SECTION_ORDER_ANY, flags)
+#endif
+
+#ifndef push_section_rng_level
+# define push_section_rng_level(section, name, level, flags)		\
+	 push_section_type(section, SECTION_TYPE_RANGES, name,		\
+			  level, flags)
+#endif
+
+#if defined(__ASSEMBLER__) || defined(__ASSEMBLY__)
+
+# ifndef DECLARE_SECTION_RANGE
+#  define DECLARE_SECTION_RANGE(section, name)				\
+    push_section_rng_level(section, name,,) ;				\
+  .globl name ;								\
+name: ;									\
+  .popsection								\
+									\
+  push_section_rng_level(section, name, ~,) ;				\
+  .popsection
+# endif
+
+#endif /* defined(__ASSEMBLER__) || defined(__ASSEMBLY__) */
+
+#endif /* _ASM_GENERIC_RANGES_H_ */
diff --git a/include/linux/ranges.h b/include/linux/ranges.h
new file mode 100644
index 000000000000..1146c7225096
--- /dev/null
+++ b/include/linux/ranges.h
@@ -0,0 +1,54 @@
+#ifndef _LINUX_RANGES_H
+#define _LINUX_RANGES_H
+/*
+ * Linux section ranges
+ *
+ * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
+ *
+ * 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/.
+ */
+#ifdef __KERNEL__
+#include <linux/sections.h>
+# include <asm/ranges.h>
+#endif /* __KERNEL__ */
+
+#ifndef __ASSEMBLY__
+
+#define SECTION_ADDR_IN_RANGE(name, addr)				\
+	 (addr >= (unsigned long) LINUX_SECTION_START(name) &&		\
+          addr <  (unsigned long) LINUX_SECTION_END(name))
+
+#define DECLARE_SECTION_RANGE(name)					\
+	DECLARE_LINUX_SECTION_RO(char, name)
+
+#define SECTION_RANGE_BEGIN(name, __section)				\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     weak,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_RNG_LEVEL(__section, name, ))))
+
+#define SECTION_RANGE_END(name, __section)				\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_RNG_LEVEL(__section, name, ~))))
+
+#define DEFINE_SECTION_RANGE(name, section)				\
+	DECLARE_LINUX_SECTION_RO(char, name);				\
+	SECTION_RANGE_BEGIN(name, section) VMLINUX_SYMBOL(name)[0] = {};\
+	SECTION_RANGE_END(name, section) VMLINUX_SYMBOL(name##__end)[0] = {};
+
+#define __LINUX_RANGE(section, name)					\
+	__attribute__((__aligned__(LINUX_SECTION_ALIGNMENT(name)),	\
+		       __section__(SECTION_RNG(section, name))))
+
+#define __LINUX_RANGE_ORDER(section, name, level)			\
+	__attribute__((__aligned__(LINUX_SECTION_ALIGNMENT(name)),	\
+		       __section__(SECTION_RNG_LEVEL(section, name, level))))
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _LINUX_RANGES_H */
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 06/13] ranges.h: add helpers to build and identify Linux section ranges
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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 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 defult trusting the asm-generic
version all around.

v3: new in this series, uses copyleft-next

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 arch/alpha/include/asm/ranges.h      |  6 ++++
 arch/arc/include/asm/ranges.h        |  6 ++++
 arch/arm/include/asm/ranges.h        |  6 ++++
 arch/arm64/include/asm/ranges.h      |  6 ++++
 arch/avr32/include/asm/ranges.h      |  6 ++++
 arch/blackfin/include/asm/ranges.h   |  6 ++++
 arch/c6x/include/asm/ranges.h        |  6 ++++
 arch/cris/include/asm/ranges.h       |  6 ++++
 arch/frv/include/asm/ranges.h        |  6 ++++
 arch/h8300/include/asm/ranges.h      |  6 ++++
 arch/hexagon/include/asm/ranges.h    |  6 ++++
 arch/ia64/include/asm/ranges.h       |  6 ++++
 arch/m32r/include/asm/ranges.h       |  6 ++++
 arch/m68k/include/asm/ranges.h       |  6 ++++
 arch/metag/include/asm/ranges.h      |  6 ++++
 arch/microblaze/include/asm/ranges.h |  6 ++++
 arch/mips/include/asm/ranges.h       |  6 ++++
 arch/mn10300/include/asm/ranges.h    |  6 ++++
 arch/nios2/include/asm/ranges.h      |  6 ++++
 arch/openrisc/include/asm/ranges.h   |  6 ++++
 arch/parisc/include/asm/ranges.h     |  6 ++++
 arch/powerpc/include/asm/ranges.h    |  6 ++++
 arch/s390/include/asm/ranges.h       |  6 ++++
 arch/score/include/asm/ranges.h      |  6 ++++
 arch/sh/include/asm/ranges.h         |  6 ++++
 arch/sparc/include/asm/ranges.h      |  6 ++++
 arch/tile/include/asm/ranges.h       |  6 ++++
 arch/um/include/asm/ranges.h         |  6 ++++
 arch/unicore32/include/asm/ranges.h  |  6 ++++
 arch/x86/include/asm/ranges.h        |  6 ++++
 arch/xtensa/include/asm/ranges.h     |  6 ++++
 include/asm-generic/ranges.h         | 70 ++++++++++++++++++++++++++++++++++++
 include/linux/ranges.h               | 54 ++++++++++++++++++++++++++++
 33 files changed, 310 insertions(+)
 create mode 100644 arch/alpha/include/asm/ranges.h
 create mode 100644 arch/arc/include/asm/ranges.h
 create mode 100644 arch/arm/include/asm/ranges.h
 create mode 100644 arch/arm64/include/asm/ranges.h
 create mode 100644 arch/avr32/include/asm/ranges.h
 create mode 100644 arch/blackfin/include/asm/ranges.h
 create mode 100644 arch/c6x/include/asm/ranges.h
 create mode 100644 arch/cris/include/asm/ranges.h
 create mode 100644 arch/frv/include/asm/ranges.h
 create mode 100644 arch/h8300/include/asm/ranges.h
 create mode 100644 arch/hexagon/include/asm/ranges.h
 create mode 100644 arch/ia64/include/asm/ranges.h
 create mode 100644 arch/m32r/include/asm/ranges.h
 create mode 100644 arch/m68k/include/asm/ranges.h
 create mode 100644 arch/metag/include/asm/ranges.h
 create mode 100644 arch/microblaze/include/asm/ranges.h
 create mode 100644 arch/mips/include/asm/ranges.h
 create mode 100644 arch/mn10300/include/asm/ranges.h
 create mode 100644 arch/nios2/include/asm/ranges.h
 create mode 100644 arch/openrisc/include/asm/ranges.h
 create mode 100644 arch/parisc/include/asm/ranges.h
 create mode 100644 arch/powerpc/include/asm/ranges.h
 create mode 100644 arch/s390/include/asm/ranges.h
 create mode 100644 arch/score/include/asm/ranges.h
 create mode 100644 arch/sh/include/asm/ranges.h
 create mode 100644 arch/sparc/include/asm/ranges.h
 create mode 100644 arch/tile/include/asm/ranges.h
 create mode 100644 arch/um/include/asm/ranges.h
 create mode 100644 arch/unicore32/include/asm/ranges.h
 create mode 100644 arch/x86/include/asm/ranges.h
 create mode 100644 arch/xtensa/include/asm/ranges.h
 create mode 100644 include/asm-generic/ranges.h
 create mode 100644 include/linux/ranges.h

diff --git a/arch/alpha/include/asm/ranges.h b/arch/alpha/include/asm/ranges.h
new file mode 100644
index 000000000000..b7bc4107bc75
--- /dev/null
+++ b/arch/alpha/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ALPHA_RANGES_H
+#define _ASM_ALPHA_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_ALPHA_RANGES_H */
diff --git a/arch/arc/include/asm/ranges.h b/arch/arc/include/asm/ranges.h
new file mode 100644
index 000000000000..a761243bf79f
--- /dev/null
+++ b/arch/arc/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARC_RANGES_H
+#define _ASM_ARC_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_ARC_RANGES_H */
diff --git a/arch/arm/include/asm/ranges.h b/arch/arm/include/asm/ranges.h
new file mode 100644
index 000000000000..fb059e205f90
--- /dev/null
+++ b/arch/arm/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARM_RANGES_H
+#define _ASM_ARM_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_ARM_RANGES_H */
diff --git a/arch/arm64/include/asm/ranges.h b/arch/arm64/include/asm/ranges.h
new file mode 100644
index 000000000000..0e0b52cc8d41
--- /dev/null
+++ b/arch/arm64/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARM64_RANGES_H
+#define _ASM_ARM64_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_ARM64_RANGES_H */
diff --git a/arch/avr32/include/asm/ranges.h b/arch/avr32/include/asm/ranges.h
new file mode 100644
index 000000000000..0f50a1af03e1
--- /dev/null
+++ b/arch/avr32/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_AVR32_RANGES_H
+#define _ASM_AVR32_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_AVR32_RANGES_H */
diff --git a/arch/blackfin/include/asm/ranges.h b/arch/blackfin/include/asm/ranges.h
new file mode 100644
index 000000000000..e1d133639a45
--- /dev/null
+++ b/arch/blackfin/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_BLACKFIN_RANGES_H
+#define _ASM_BLACKFIN_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_BLACKFIN_RANGES_H */
diff --git a/arch/c6x/include/asm/ranges.h b/arch/c6x/include/asm/ranges.h
new file mode 100644
index 000000000000..0e8e6e149d55
--- /dev/null
+++ b/arch/c6x/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_C6X_RANGES_H
+#define _ASM_C6X_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_C6X_RANGES_H */
diff --git a/arch/cris/include/asm/ranges.h b/arch/cris/include/asm/ranges.h
new file mode 100644
index 000000000000..8567f55ae4ea
--- /dev/null
+++ b/arch/cris/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_CRIS_RANGES_H
+#define _ASM_CRIS_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_CRIS_RANGES_H */
diff --git a/arch/frv/include/asm/ranges.h b/arch/frv/include/asm/ranges.h
new file mode 100644
index 000000000000..f11a6f0fb0bd
--- /dev/null
+++ b/arch/frv/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_FRV_RANGES_H
+#define _ASM_FRV_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_FRV_RANGES_H */
diff --git a/arch/h8300/include/asm/ranges.h b/arch/h8300/include/asm/ranges.h
new file mode 100644
index 000000000000..ab08bd6bd067
--- /dev/null
+++ b/arch/h8300/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_H8300_RANGES_H
+#define _ASM_H8300_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_H8300_RANGES_H */
diff --git a/arch/hexagon/include/asm/ranges.h b/arch/hexagon/include/asm/ranges.h
new file mode 100644
index 000000000000..56e5241abc6b
--- /dev/null
+++ b/arch/hexagon/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_HEXAGON_RANGES_H
+#define _ASM_HEXAGON_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_HEXAGON_RANGES_H */
diff --git a/arch/ia64/include/asm/ranges.h b/arch/ia64/include/asm/ranges.h
new file mode 100644
index 000000000000..4e69cbcfd0e7
--- /dev/null
+++ b/arch/ia64/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_IA64_RANGES_H
+#define _ASM_IA64_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_IA64_RANGES_H */
diff --git a/arch/m32r/include/asm/ranges.h b/arch/m32r/include/asm/ranges.h
new file mode 100644
index 000000000000..dd33a0b94de4
--- /dev/null
+++ b/arch/m32r/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_M32R_RANGES_H
+#define _ASM_M32R_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_M32R_RANGES_H */
diff --git a/arch/m68k/include/asm/ranges.h b/arch/m68k/include/asm/ranges.h
new file mode 100644
index 000000000000..292a00baa73e
--- /dev/null
+++ b/arch/m68k/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_M68K_RANGES_H
+#define _ASM_M68K_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_M68K_RANGES_H */
diff --git a/arch/metag/include/asm/ranges.h b/arch/metag/include/asm/ranges.h
new file mode 100644
index 000000000000..42a77c098c85
--- /dev/null
+++ b/arch/metag/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_METAG_RANGES_H
+#define _ASM_METAG_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_METAG_RANGES_H */
diff --git a/arch/microblaze/include/asm/ranges.h b/arch/microblaze/include/asm/ranges.h
new file mode 100644
index 000000000000..48d58e38f1e1
--- /dev/null
+++ b/arch/microblaze/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MICROBLAZE_RANGES_H
+#define _ASM_MICROBLAZE_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_MICROBLAZE_RANGES_H */
diff --git a/arch/mips/include/asm/ranges.h b/arch/mips/include/asm/ranges.h
new file mode 100644
index 000000000000..675a55cd3719
--- /dev/null
+++ b/arch/mips/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MIPS_RANGES_H
+#define _ASM_MIPS_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_MIPS_RANGES_H */
diff --git a/arch/mn10300/include/asm/ranges.h b/arch/mn10300/include/asm/ranges.h
new file mode 100644
index 000000000000..fb7f43a3c19d
--- /dev/null
+++ b/arch/mn10300/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MN10300_RANGES_H
+#define _ASM_MN10300_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_MN10300_RANGES_H */
diff --git a/arch/nios2/include/asm/ranges.h b/arch/nios2/include/asm/ranges.h
new file mode 100644
index 000000000000..ab1991981c0f
--- /dev/null
+++ b/arch/nios2/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_NIOS2_RANGES_H
+#define _ASM_NIOS2_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_NIOS2_RANGES_H */
diff --git a/arch/openrisc/include/asm/ranges.h b/arch/openrisc/include/asm/ranges.h
new file mode 100644
index 000000000000..a64be842983f
--- /dev/null
+++ b/arch/openrisc/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_OPENRISC_RANGES_H
+#define _ASM_OPENRISC_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_OPENRISC_RANGES_H */
diff --git a/arch/parisc/include/asm/ranges.h b/arch/parisc/include/asm/ranges.h
new file mode 100644
index 000000000000..dd6b5c215941
--- /dev/null
+++ b/arch/parisc/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_PARISC_RANGES_H
+#define _ASM_PARISC_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_PARISC_RANGES_H */
diff --git a/arch/powerpc/include/asm/ranges.h b/arch/powerpc/include/asm/ranges.h
new file mode 100644
index 000000000000..240c51a210d4
--- /dev/null
+++ b/arch/powerpc/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_POWERPC_RANGES_H
+#define _ASM_POWERPC_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_POWERPC_RANGES_H */
diff --git a/arch/s390/include/asm/ranges.h b/arch/s390/include/asm/ranges.h
new file mode 100644
index 000000000000..d4788451f176
--- /dev/null
+++ b/arch/s390/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_S390_RANGES_H
+#define _ASM_S390_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_S390_RANGES_H */
diff --git a/arch/score/include/asm/ranges.h b/arch/score/include/asm/ranges.h
new file mode 100644
index 000000000000..d67f859eeda3
--- /dev/null
+++ b/arch/score/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SCORE_RANGES_H
+#define _ASM_SCORE_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_SCORE_RANGES_H */
diff --git a/arch/sh/include/asm/ranges.h b/arch/sh/include/asm/ranges.h
new file mode 100644
index 000000000000..99df0b65f40a
--- /dev/null
+++ b/arch/sh/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SH_RANGES_H
+#define _ASM_SH_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_SH_RANGES_H */
diff --git a/arch/sparc/include/asm/ranges.h b/arch/sparc/include/asm/ranges.h
new file mode 100644
index 000000000000..8ff4765ccd9b
--- /dev/null
+++ b/arch/sparc/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SPARC_RANGES_H
+#define _ASM_SPARC_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_SPARC_RANGES_H */
diff --git a/arch/tile/include/asm/ranges.h b/arch/tile/include/asm/ranges.h
new file mode 100644
index 000000000000..ceda3fb075e0
--- /dev/null
+++ b/arch/tile/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_TILE_RANGES_H
+#define _ASM_TILE_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_TILE_RANGES_H */
diff --git a/arch/um/include/asm/ranges.h b/arch/um/include/asm/ranges.h
new file mode 100644
index 000000000000..7c9c20e47879
--- /dev/null
+++ b/arch/um/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_UM_RANGES_H
+#define _ASM_UM_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_UM_RANGES_H */
diff --git a/arch/unicore32/include/asm/ranges.h b/arch/unicore32/include/asm/ranges.h
new file mode 100644
index 000000000000..92526340d73c
--- /dev/null
+++ b/arch/unicore32/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_UNICORE32_RANGES_H
+#define _ASM_UNICORE32_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_UNICORE32_RANGES_H */
diff --git a/arch/x86/include/asm/ranges.h b/arch/x86/include/asm/ranges.h
new file mode 100644
index 000000000000..4a0c824d4082
--- /dev/null
+++ b/arch/x86/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_X86_RANGES_H
+#define _ASM_X86_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_X86_RANGES_H */
diff --git a/arch/xtensa/include/asm/ranges.h b/arch/xtensa/include/asm/ranges.h
new file mode 100644
index 000000000000..c7360d1c9c85
--- /dev/null
+++ b/arch/xtensa/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_XTENSA_RANGES_H
+#define _ASM_XTENSA_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_XTENSA_RANGES_H */
diff --git a/include/asm-generic/ranges.h b/include/asm-generic/ranges.h
new file mode 100644
index 000000000000..0d54c632f714
--- /dev/null
+++ b/include/asm-generic/ranges.h
@@ -0,0 +1,70 @@
+#ifndef _ASM_GENERIC_RANGES_H_
+#define _ASM_GENERIC_RANGES_H_
+/*
+ * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
+ *
+ * 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/.
+ */
+#ifdef __KERNEL__
+# include <asm/sections.h>
+#endif /* __KERNEL__ */
+
+#define SECTION_TYPE_RANGES	rng
+
+#define SECTION_RNG(section, name)					\
+	SECTION_TYPE(section, SECTION_TYPE_RANGES, name,		\
+		     SECTION_ORDER_ANY)
+
+#define SECTION_RNG_LEVEL(section, name, level)				\
+	SECTION_TYPE(section, SECTION_TYPE_RANGES, name, level)
+
+#define SECTION_RANGE_ALL(section)					\
+	SECTION_TYPE_ALL(section,SECTION_TYPE_RANGES)
+
+#ifndef section_rng
+# define section_rng(section, name, flags)				\
+	 section_type(section, SECTION_TYPE_RANGES, name,		\
+		      SECTION_ORDER_ANY, flags)
+#endif
+
+#ifndef section_rng_asmtype
+# define section_rng_asmtype(section, name, flags, asmtype)		\
+	 section_type_asmtype(section, SECTION_TYPE_RANGES, name,	\
+			      SECTION_ORDER_ANY, flags, asmtype)
+#endif
+
+#ifndef section_rng_level
+# define section_rng_level(section, name, level, flags)			\
+	 section_type(section, SECTION_TYPE_RANGES, name, level, flags)
+#endif
+
+#ifndef push_section_rng
+# define push_section_rng(section, name, flags)				\
+	 push_section_type(section, SECTION_TYPE_RANGES, name,		\
+			  SECTION_ORDER_ANY, flags)
+#endif
+
+#ifndef push_section_rng_level
+# define push_section_rng_level(section, name, level, flags)		\
+	 push_section_type(section, SECTION_TYPE_RANGES, name,		\
+			  level, flags)
+#endif
+
+#if defined(__ASSEMBLER__) || defined(__ASSEMBLY__)
+
+# ifndef DECLARE_SECTION_RANGE
+#  define DECLARE_SECTION_RANGE(section, name)				\
+    push_section_rng_level(section, name,,) ;				\
+  .globl name ;								\
+name: ;									\
+  .popsection								\
+									\
+  push_section_rng_level(section, name, ~,) ;				\
+  .popsection
+# endif
+
+#endif /* defined(__ASSEMBLER__) || defined(__ASSEMBLY__) */
+
+#endif /* _ASM_GENERIC_RANGES_H_ */
diff --git a/include/linux/ranges.h b/include/linux/ranges.h
new file mode 100644
index 000000000000..1146c7225096
--- /dev/null
+++ b/include/linux/ranges.h
@@ -0,0 +1,54 @@
+#ifndef _LINUX_RANGES_H
+#define _LINUX_RANGES_H
+/*
+ * Linux section ranges
+ *
+ * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
+ *
+ * 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/.
+ */
+#ifdef __KERNEL__
+#include <linux/sections.h>
+# include <asm/ranges.h>
+#endif /* __KERNEL__ */
+
+#ifndef __ASSEMBLY__
+
+#define SECTION_ADDR_IN_RANGE(name, addr)				\
+	 (addr >= (unsigned long) LINUX_SECTION_START(name) &&		\
+          addr <  (unsigned long) LINUX_SECTION_END(name))
+
+#define DECLARE_SECTION_RANGE(name)					\
+	DECLARE_LINUX_SECTION_RO(char, name)
+
+#define SECTION_RANGE_BEGIN(name, __section)				\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     weak,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_RNG_LEVEL(__section, name, ))))
+
+#define SECTION_RANGE_END(name, __section)				\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_RNG_LEVEL(__section, name, ~))))
+
+#define DEFINE_SECTION_RANGE(name, section)				\
+	DECLARE_LINUX_SECTION_RO(char, name);				\
+	SECTION_RANGE_BEGIN(name, section) VMLINUX_SYMBOL(name)[0] = {};\
+	SECTION_RANGE_END(name, section) VMLINUX_SYMBOL(name##__end)[0] = {};
+
+#define __LINUX_RANGE(section, name)					\
+	__attribute__((__aligned__(LINUX_SECTION_ALIGNMENT(name)),	\
+		       __section__(SECTION_RNG(section, name))))
+
+#define __LINUX_RANGE_ORDER(section, name, level)			\
+	__attribute__((__aligned__(LINUX_SECTION_ALIGNMENT(name)),	\
+		       __section__(SECTION_RNG_LEVEL(section, name, level))))
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _LINUX_RANGES_H */
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 06/13] ranges.h: add helpers to build and identify Linux section ranges
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe, Luis R. Rodriguez

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 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 defult trusting the asm-generic
version all around.

v3: new in this series, uses copyleft-next

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 arch/alpha/include/asm/ranges.h      |  6 ++++
 arch/arc/include/asm/ranges.h        |  6 ++++
 arch/arm/include/asm/ranges.h        |  6 ++++
 arch/arm64/include/asm/ranges.h      |  6 ++++
 arch/avr32/include/asm/ranges.h      |  6 ++++
 arch/blackfin/include/asm/ranges.h   |  6 ++++
 arch/c6x/include/asm/ranges.h        |  6 ++++
 arch/cris/include/asm/ranges.h       |  6 ++++
 arch/frv/include/asm/ranges.h        |  6 ++++
 arch/h8300/include/asm/ranges.h      |  6 ++++
 arch/hexagon/include/asm/ranges.h    |  6 ++++
 arch/ia64/include/asm/ranges.h       |  6 ++++
 arch/m32r/include/asm/ranges.h       |  6 ++++
 arch/m68k/include/asm/ranges.h       |  6 ++++
 arch/metag/include/asm/ranges.h      |  6 ++++
 arch/microblaze/include/asm/ranges.h |  6 ++++
 arch/mips/include/asm/ranges.h       |  6 ++++
 arch/mn10300/include/asm/ranges.h    |  6 ++++
 arch/nios2/include/asm/ranges.h      |  6 ++++
 arch/openrisc/include/asm/ranges.h   |  6 ++++
 arch/parisc/include/asm/ranges.h     |  6 ++++
 arch/powerpc/include/asm/ranges.h    |  6 ++++
 arch/s390/include/asm/ranges.h       |  6 ++++
 arch/score/include/asm/ranges.h      |  6 ++++
 arch/sh/include/asm/ranges.h         |  6 ++++
 arch/sparc/include/asm/ranges.h      |  6 ++++
 arch/tile/include/asm/ranges.h       |  6 ++++
 arch/um/include/asm/ranges.h         |  6 ++++
 arch/unicore32/include/asm/ranges.h  |  6 ++++
 arch/x86/include/asm/ranges.h        |  6 ++++
 arch/xtensa/include/asm/ranges.h     |  6 ++++
 include/asm-generic/ranges.h         | 70 ++++++++++++++++++++++++++++++++++++
 include/linux/ranges.h               | 54 ++++++++++++++++++++++++++++
 33 files changed, 310 insertions(+)
 create mode 100644 arch/alpha/include/asm/ranges.h
 create mode 100644 arch/arc/include/asm/ranges.h
 create mode 100644 arch/arm/include/asm/ranges.h
 create mode 100644 arch/arm64/include/asm/ranges.h
 create mode 100644 arch/avr32/include/asm/ranges.h
 create mode 100644 arch/blackfin/include/asm/ranges.h
 create mode 100644 arch/c6x/include/asm/ranges.h
 create mode 100644 arch/cris/include/asm/ranges.h
 create mode 100644 arch/frv/include/asm/ranges.h
 create mode 100644 arch/h8300/include/asm/ranges.h
 create mode 100644 arch/hexagon/include/asm/ranges.h
 create mode 100644 arch/ia64/include/asm/ranges.h
 create mode 100644 arch/m32r/include/asm/ranges.h
 create mode 100644 arch/m68k/include/asm/ranges.h
 create mode 100644 arch/metag/include/asm/ranges.h
 create mode 100644 arch/microblaze/include/asm/ranges.h
 create mode 100644 arch/mips/include/asm/ranges.h
 create mode 100644 arch/mn10300/include/asm/ranges.h
 create mode 100644 arch/nios2/include/asm/ranges.h
 create mode 100644 arch/openrisc/include/asm/ranges.h
 create mode 100644 arch/parisc/include/asm/ranges.h
 create mode 100644 arch/powerpc/include/asm/ranges.h
 create mode 100644 arch/s390/include/asm/ranges.h
 create mode 100644 arch/score/include/asm/ranges.h
 create mode 100644 arch/sh/include/asm/ranges.h
 create mode 100644 arch/sparc/include/asm/ranges.h
 create mode 100644 arch/tile/include/asm/ranges.h
 create mode 100644 arch/um/include/asm/ranges.h
 create mode 100644 arch/unicore32/include/asm/ranges.h
 create mode 100644 arch/x86/include/asm/ranges.h
 create mode 100644 arch/xtensa/include/asm/ranges.h
 create mode 100644 include/asm-generic/ranges.h
 create mode 100644 include/linux/ranges.h

diff --git a/arch/alpha/include/asm/ranges.h b/arch/alpha/include/asm/ranges.h
new file mode 100644
index 000000000000..b7bc4107bc75
--- /dev/null
+++ b/arch/alpha/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ALPHA_RANGES_H
+#define _ASM_ALPHA_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_ALPHA_RANGES_H */
diff --git a/arch/arc/include/asm/ranges.h b/arch/arc/include/asm/ranges.h
new file mode 100644
index 000000000000..a761243bf79f
--- /dev/null
+++ b/arch/arc/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARC_RANGES_H
+#define _ASM_ARC_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_ARC_RANGES_H */
diff --git a/arch/arm/include/asm/ranges.h b/arch/arm/include/asm/ranges.h
new file mode 100644
index 000000000000..fb059e205f90
--- /dev/null
+++ b/arch/arm/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARM_RANGES_H
+#define _ASM_ARM_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_ARM_RANGES_H */
diff --git a/arch/arm64/include/asm/ranges.h b/arch/arm64/include/asm/ranges.h
new file mode 100644
index 000000000000..0e0b52cc8d41
--- /dev/null
+++ b/arch/arm64/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARM64_RANGES_H
+#define _ASM_ARM64_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_ARM64_RANGES_H */
diff --git a/arch/avr32/include/asm/ranges.h b/arch/avr32/include/asm/ranges.h
new file mode 100644
index 000000000000..0f50a1af03e1
--- /dev/null
+++ b/arch/avr32/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_AVR32_RANGES_H
+#define _ASM_AVR32_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_AVR32_RANGES_H */
diff --git a/arch/blackfin/include/asm/ranges.h b/arch/blackfin/include/asm/ranges.h
new file mode 100644
index 000000000000..e1d133639a45
--- /dev/null
+++ b/arch/blackfin/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_BLACKFIN_RANGES_H
+#define _ASM_BLACKFIN_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_BLACKFIN_RANGES_H */
diff --git a/arch/c6x/include/asm/ranges.h b/arch/c6x/include/asm/ranges.h
new file mode 100644
index 000000000000..0e8e6e149d55
--- /dev/null
+++ b/arch/c6x/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_C6X_RANGES_H
+#define _ASM_C6X_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_C6X_RANGES_H */
diff --git a/arch/cris/include/asm/ranges.h b/arch/cris/include/asm/ranges.h
new file mode 100644
index 000000000000..8567f55ae4ea
--- /dev/null
+++ b/arch/cris/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_CRIS_RANGES_H
+#define _ASM_CRIS_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_CRIS_RANGES_H */
diff --git a/arch/frv/include/asm/ranges.h b/arch/frv/include/asm/ranges.h
new file mode 100644
index 000000000000..f11a6f0fb0bd
--- /dev/null
+++ b/arch/frv/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_FRV_RANGES_H
+#define _ASM_FRV_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_FRV_RANGES_H */
diff --git a/arch/h8300/include/asm/ranges.h b/arch/h8300/include/asm/ranges.h
new file mode 100644
index 000000000000..ab08bd6bd067
--- /dev/null
+++ b/arch/h8300/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_H8300_RANGES_H
+#define _ASM_H8300_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_H8300_RANGES_H */
diff --git a/arch/hexagon/include/asm/ranges.h b/arch/hexagon/include/asm/ranges.h
new file mode 100644
index 000000000000..56e5241abc6b
--- /dev/null
+++ b/arch/hexagon/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_HEXAGON_RANGES_H
+#define _ASM_HEXAGON_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_HEXAGON_RANGES_H */
diff --git a/arch/ia64/include/asm/ranges.h b/arch/ia64/include/asm/ranges.h
new file mode 100644
index 000000000000..4e69cbcfd0e7
--- /dev/null
+++ b/arch/ia64/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_IA64_RANGES_H
+#define _ASM_IA64_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_IA64_RANGES_H */
diff --git a/arch/m32r/include/asm/ranges.h b/arch/m32r/include/asm/ranges.h
new file mode 100644
index 000000000000..dd33a0b94de4
--- /dev/null
+++ b/arch/m32r/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_M32R_RANGES_H
+#define _ASM_M32R_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_M32R_RANGES_H */
diff --git a/arch/m68k/include/asm/ranges.h b/arch/m68k/include/asm/ranges.h
new file mode 100644
index 000000000000..292a00baa73e
--- /dev/null
+++ b/arch/m68k/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_M68K_RANGES_H
+#define _ASM_M68K_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_M68K_RANGES_H */
diff --git a/arch/metag/include/asm/ranges.h b/arch/metag/include/asm/ranges.h
new file mode 100644
index 000000000000..42a77c098c85
--- /dev/null
+++ b/arch/metag/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_METAG_RANGES_H
+#define _ASM_METAG_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_METAG_RANGES_H */
diff --git a/arch/microblaze/include/asm/ranges.h b/arch/microblaze/include/asm/ranges.h
new file mode 100644
index 000000000000..48d58e38f1e1
--- /dev/null
+++ b/arch/microblaze/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MICROBLAZE_RANGES_H
+#define _ASM_MICROBLAZE_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_MICROBLAZE_RANGES_H */
diff --git a/arch/mips/include/asm/ranges.h b/arch/mips/include/asm/ranges.h
new file mode 100644
index 000000000000..675a55cd3719
--- /dev/null
+++ b/arch/mips/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MIPS_RANGES_H
+#define _ASM_MIPS_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_MIPS_RANGES_H */
diff --git a/arch/mn10300/include/asm/ranges.h b/arch/mn10300/include/asm/ranges.h
new file mode 100644
index 000000000000..fb7f43a3c19d
--- /dev/null
+++ b/arch/mn10300/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MN10300_RANGES_H
+#define _ASM_MN10300_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_MN10300_RANGES_H */
diff --git a/arch/nios2/include/asm/ranges.h b/arch/nios2/include/asm/ranges.h
new file mode 100644
index 000000000000..ab1991981c0f
--- /dev/null
+++ b/arch/nios2/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_NIOS2_RANGES_H
+#define _ASM_NIOS2_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_NIOS2_RANGES_H */
diff --git a/arch/openrisc/include/asm/ranges.h b/arch/openrisc/include/asm/ranges.h
new file mode 100644
index 000000000000..a64be842983f
--- /dev/null
+++ b/arch/openrisc/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_OPENRISC_RANGES_H
+#define _ASM_OPENRISC_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_OPENRISC_RANGES_H */
diff --git a/arch/parisc/include/asm/ranges.h b/arch/parisc/include/asm/ranges.h
new file mode 100644
index 000000000000..dd6b5c215941
--- /dev/null
+++ b/arch/parisc/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_PARISC_RANGES_H
+#define _ASM_PARISC_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_PARISC_RANGES_H */
diff --git a/arch/powerpc/include/asm/ranges.h b/arch/powerpc/include/asm/ranges.h
new file mode 100644
index 000000000000..240c51a210d4
--- /dev/null
+++ b/arch/powerpc/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_POWERPC_RANGES_H
+#define _ASM_POWERPC_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_POWERPC_RANGES_H */
diff --git a/arch/s390/include/asm/ranges.h b/arch/s390/include/asm/ranges.h
new file mode 100644
index 000000000000..d4788451f176
--- /dev/null
+++ b/arch/s390/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_S390_RANGES_H
+#define _ASM_S390_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_S390_RANGES_H */
diff --git a/arch/score/include/asm/ranges.h b/arch/score/include/asm/ranges.h
new file mode 100644
index 000000000000..d67f859eeda3
--- /dev/null
+++ b/arch/score/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SCORE_RANGES_H
+#define _ASM_SCORE_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_SCORE_RANGES_H */
diff --git a/arch/sh/include/asm/ranges.h b/arch/sh/include/asm/ranges.h
new file mode 100644
index 000000000000..99df0b65f40a
--- /dev/null
+++ b/arch/sh/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SH_RANGES_H
+#define _ASM_SH_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_SH_RANGES_H */
diff --git a/arch/sparc/include/asm/ranges.h b/arch/sparc/include/asm/ranges.h
new file mode 100644
index 000000000000..8ff4765ccd9b
--- /dev/null
+++ b/arch/sparc/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SPARC_RANGES_H
+#define _ASM_SPARC_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_SPARC_RANGES_H */
diff --git a/arch/tile/include/asm/ranges.h b/arch/tile/include/asm/ranges.h
new file mode 100644
index 000000000000..ceda3fb075e0
--- /dev/null
+++ b/arch/tile/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_TILE_RANGES_H
+#define _ASM_TILE_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_TILE_RANGES_H */
diff --git a/arch/um/include/asm/ranges.h b/arch/um/include/asm/ranges.h
new file mode 100644
index 000000000000..7c9c20e47879
--- /dev/null
+++ b/arch/um/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_UM_RANGES_H
+#define _ASM_UM_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_UM_RANGES_H */
diff --git a/arch/unicore32/include/asm/ranges.h b/arch/unicore32/include/asm/ranges.h
new file mode 100644
index 000000000000..92526340d73c
--- /dev/null
+++ b/arch/unicore32/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_UNICORE32_RANGES_H
+#define _ASM_UNICORE32_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_UNICORE32_RANGES_H */
diff --git a/arch/x86/include/asm/ranges.h b/arch/x86/include/asm/ranges.h
new file mode 100644
index 000000000000..4a0c824d4082
--- /dev/null
+++ b/arch/x86/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_X86_RANGES_H
+#define _ASM_X86_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_X86_RANGES_H */
diff --git a/arch/xtensa/include/asm/ranges.h b/arch/xtensa/include/asm/ranges.h
new file mode 100644
index 000000000000..c7360d1c9c85
--- /dev/null
+++ b/arch/xtensa/include/asm/ranges.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_XTENSA_RANGES_H
+#define _ASM_XTENSA_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif /* _ASM_XTENSA_RANGES_H */
diff --git a/include/asm-generic/ranges.h b/include/asm-generic/ranges.h
new file mode 100644
index 000000000000..0d54c632f714
--- /dev/null
+++ b/include/asm-generic/ranges.h
@@ -0,0 +1,70 @@
+#ifndef _ASM_GENERIC_RANGES_H_
+#define _ASM_GENERIC_RANGES_H_
+/*
+ * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
+ *
+ * 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/.
+ */
+#ifdef __KERNEL__
+# include <asm/sections.h>
+#endif /* __KERNEL__ */
+
+#define SECTION_TYPE_RANGES	rng
+
+#define SECTION_RNG(section, name)					\
+	SECTION_TYPE(section, SECTION_TYPE_RANGES, name,		\
+		     SECTION_ORDER_ANY)
+
+#define SECTION_RNG_LEVEL(section, name, level)				\
+	SECTION_TYPE(section, SECTION_TYPE_RANGES, name, level)
+
+#define SECTION_RANGE_ALL(section)					\
+	SECTION_TYPE_ALL(section,SECTION_TYPE_RANGES)
+
+#ifndef section_rng
+# define section_rng(section, name, flags)				\
+	 section_type(section, SECTION_TYPE_RANGES, name,		\
+		      SECTION_ORDER_ANY, flags)
+#endif
+
+#ifndef section_rng_asmtype
+# define section_rng_asmtype(section, name, flags, asmtype)		\
+	 section_type_asmtype(section, SECTION_TYPE_RANGES, name,	\
+			      SECTION_ORDER_ANY, flags, asmtype)
+#endif
+
+#ifndef section_rng_level
+# define section_rng_level(section, name, level, flags)			\
+	 section_type(section, SECTION_TYPE_RANGES, name, level, flags)
+#endif
+
+#ifndef push_section_rng
+# define push_section_rng(section, name, flags)				\
+	 push_section_type(section, SECTION_TYPE_RANGES, name,		\
+			  SECTION_ORDER_ANY, flags)
+#endif
+
+#ifndef push_section_rng_level
+# define push_section_rng_level(section, name, level, flags)		\
+	 push_section_type(section, SECTION_TYPE_RANGES, name,		\
+			  level, flags)
+#endif
+
+#if defined(__ASSEMBLER__) || defined(__ASSEMBLY__)
+
+# ifndef DECLARE_SECTION_RANGE
+#  define DECLARE_SECTION_RANGE(section, name)				\
+    push_section_rng_level(section, name,,) ;				\
+  .globl name ;								\
+name: ;									\
+  .popsection								\
+									\
+  push_section_rng_level(section, name, ~,) ;				\
+  .popsection
+# endif
+
+#endif /* defined(__ASSEMBLER__) || defined(__ASSEMBLY__) */
+
+#endif /* _ASM_GENERIC_RANGES_H_ */
diff --git a/include/linux/ranges.h b/include/linux/ranges.h
new file mode 100644
index 000000000000..1146c7225096
--- /dev/null
+++ b/include/linux/ranges.h
@@ -0,0 +1,54 @@
+#ifndef _LINUX_RANGES_H
+#define _LINUX_RANGES_H
+/*
+ * Linux section ranges
+ *
+ * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
+ *
+ * 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/.
+ */
+#ifdef __KERNEL__
+#include <linux/sections.h>
+# include <asm/ranges.h>
+#endif /* __KERNEL__ */
+
+#ifndef __ASSEMBLY__
+
+#define SECTION_ADDR_IN_RANGE(name, addr)				\
+	 (addr >= (unsigned long) LINUX_SECTION_START(name) &&		\
+          addr <  (unsigned long) LINUX_SECTION_END(name))
+
+#define DECLARE_SECTION_RANGE(name)					\
+	DECLARE_LINUX_SECTION_RO(char, name)
+
+#define SECTION_RANGE_BEGIN(name, __section)				\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     weak,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_RNG_LEVEL(__section, name, ))))
+
+#define SECTION_RANGE_END(name, __section)				\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_RNG_LEVEL(__section, name, ~))))
+
+#define DEFINE_SECTION_RANGE(name, section)				\
+	DECLARE_LINUX_SECTION_RO(char, name);				\
+	SECTION_RANGE_BEGIN(name, section) VMLINUX_SYMBOL(name)[0] = {};\
+	SECTION_RANGE_END(name, section) VMLINUX_SYMBOL(name##__end)[0] = {};
+
+#define __LINUX_RANGE(section, name)					\
+	__attribute__((__aligned__(LINUX_SECTION_ALIGNMENT(name)),	\
+		       __section__(SECTION_RNG(section, name))))
+
+#define __LINUX_RANGE_ORDER(section, name, level)			\
+	__attribute__((__aligned__(LINUX_SECTION_ALIGNMENT(name)),	\
+		       __section__(SECTION_RNG_LEVEL(section, name, level))))
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _LINUX_RANGES_H */
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 07/13] tables.h: add linker table support
  2016-07-22 21:24 ` Luis R. Rodriguez
  (?)
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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
originally based on Michael Brown's iPXE's linker table solution but
has been significantly modified to fit Linux's use in its integration.

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.

Bit rotting avoidance is enabled by *granting the option* to force
compilation of code and only enable linking object code in when
specific features have been enabled. It accomplishes this by using
linker sections, the lightweight feature ordering of code is enabled
by taking advantage of the old binutils ld SORT() on features
specific sections.

Contrary to iPXE's solution, which strives to force compilation
of all features, Linux' solution strives to encourage usage of linker
tables to force compilation of code *only on designated code*. Linker
tables can be used without requiring one to force code compilation
of features that use it though, to take advantage of the simplification
of init sequences.

Linux code that uses linker tables *and* wishes to always require
compilation but selectively linking must use new kbuild target object
that helps accomplishes this, table-y. Linux code that uses linker
tables but does not want to require forcing compilation can use the
good 'ol obj-y targets.

Used commit 67a10ef000cb7 from iPXE upstream [0] as the starting point
for development and evaluation of Linux's integration, further changes
made and evaluation of different linker table options for Linux are
available on the linker-table userspace tree [1].

[0] git://git.ipxe.org/ipxe.git
[1] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linker-tables.git/

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.

Cc: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 Documentation/DocBook/Makefile           |   2 +-
 Documentation/DocBook/linker-tables.tmpl | 166 +++++++++
 Documentation/kbuild/makefiles.txt       |  19 +
 arch/alpha/include/asm/tables.h          |   6 +
 arch/arc/include/asm/tables.h            |   6 +
 arch/arm/include/asm/tables.h            |   6 +
 arch/arm64/include/asm/tables.h          |   6 +
 arch/avr32/include/asm/tables.h          |   6 +
 arch/blackfin/include/asm/tables.h       |   6 +
 arch/c6x/include/asm/tables.h            |   6 +
 arch/cris/include/asm/tables.h           |   6 +
 arch/frv/include/asm/tables.h            |   6 +
 arch/h8300/include/asm/tables.h          |   6 +
 arch/hexagon/include/asm/tables.h        |   6 +
 arch/ia64/include/asm/tables.h           |   6 +
 arch/m32r/include/asm/tables.h           |   6 +
 arch/m68k/include/asm/tables.h           |   6 +
 arch/metag/include/asm/tables.h          |   6 +
 arch/microblaze/include/asm/tables.h     |   6 +
 arch/mips/include/asm/tables.h           |   6 +
 arch/mn10300/include/asm/tables.h        |   6 +
 arch/nios2/include/asm/tables.h          |   6 +
 arch/openrisc/include/asm/tables.h       |   6 +
 arch/parisc/include/asm/tables.h         |   6 +
 arch/powerpc/include/asm/tables.h        |   6 +
 arch/s390/include/asm/tables.h           |   6 +
 arch/score/include/asm/tables.h          |   6 +
 arch/sh/include/asm/tables.h             |   6 +
 arch/sparc/include/asm/tables.h          |   6 +
 arch/tile/include/asm/tables.h           |   6 +
 arch/um/include/asm/tables.h             |   6 +
 arch/unicore32/include/asm/tables.h      |   6 +
 arch/x86/include/asm/tables.h            |   6 +
 arch/x86/tools/relocs.c                  |   3 +
 arch/xtensa/include/asm/tables.h         |   6 +
 include/asm-generic/tables.h             |  70 ++++
 include/asm-generic/vmlinux.lds.h        |   9 +-
 include/linux/tables.h                   | 597 +++++++++++++++++++++++++++++++
 scripts/Makefile.build                   |   4 +-
 scripts/Makefile.clean                   |   1 +
 scripts/Makefile.lib                     |  12 +
 tools/include/linux/sections.h           |  13 +
 42 files changed, 1078 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/DocBook/linker-tables.tmpl
 create mode 100644 arch/alpha/include/asm/tables.h
 create mode 100644 arch/arc/include/asm/tables.h
 create mode 100644 arch/arm/include/asm/tables.h
 create mode 100644 arch/arm64/include/asm/tables.h
 create mode 100644 arch/avr32/include/asm/tables.h
 create mode 100644 arch/blackfin/include/asm/tables.h
 create mode 100644 arch/c6x/include/asm/tables.h
 create mode 100644 arch/cris/include/asm/tables.h
 create mode 100644 arch/frv/include/asm/tables.h
 create mode 100644 arch/h8300/include/asm/tables.h
 create mode 100644 arch/hexagon/include/asm/tables.h
 create mode 100644 arch/ia64/include/asm/tables.h
 create mode 100644 arch/m32r/include/asm/tables.h
 create mode 100644 arch/m68k/include/asm/tables.h
 create mode 100644 arch/metag/include/asm/tables.h
 create mode 100644 arch/microblaze/include/asm/tables.h
 create mode 100644 arch/mips/include/asm/tables.h
 create mode 100644 arch/mn10300/include/asm/tables.h
 create mode 100644 arch/nios2/include/asm/tables.h
 create mode 100644 arch/openrisc/include/asm/tables.h
 create mode 100644 arch/parisc/include/asm/tables.h
 create mode 100644 arch/powerpc/include/asm/tables.h
 create mode 100644 arch/s390/include/asm/tables.h
 create mode 100644 arch/score/include/asm/tables.h
 create mode 100644 arch/sh/include/asm/tables.h
 create mode 100644 arch/sparc/include/asm/tables.h
 create mode 100644 arch/tile/include/asm/tables.h
 create mode 100644 arch/um/include/asm/tables.h
 create mode 100644 arch/unicore32/include/asm/tables.h
 create mode 100644 arch/x86/include/asm/tables.h
 create mode 100644 arch/xtensa/include/asm/tables.h
 create mode 100644 include/asm-generic/tables.h
 create mode 100644 include/linux/tables.h
 create mode 100644 tools/include/linux/sections.h

diff --git a/Documentation/DocBook/Makefile b/Documentation/DocBook/Makefile
index 1b2ac4731418..b78365cc3cd1 100644
--- a/Documentation/DocBook/Makefile
+++ b/Documentation/DocBook/Makefile
@@ -18,7 +18,7 @@ DOCBOOKS := z8530book.xml device-drivers.xml \
 	    alsa-driver-api.xml writing-an-alsa-driver.xml \
 	    tracepoint.xml media_api.xml w1.xml \
 	    writing_musb_glue_layer.xml crypto-API.xml iio.xml \
-	    sections.xml
+	    sections.xml linker-tables.xml
 
 include Documentation/DocBook/media/Makefile
 
diff --git a/Documentation/DocBook/linker-tables.tmpl b/Documentation/DocBook/linker-tables.tmpl
new file mode 100644
index 000000000000..fba90c61eee1
--- /dev/null
+++ b/Documentation/DocBook/linker-tables.tmpl
@@ -0,0 +1,166 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+	"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
+<set>
+  <setinfo>
+    <title>Linux linker tables</title>
+    <subtitle>
+      Explains Linux' linker tables work.
+    </subtitle>
+
+    <copyright>
+      <year>2015-2016</year>
+      <holder>Luis R. Rodriguez</holder>
+    </copyright>
+
+    <authorgroup>
+      <author>
+        <firstname>Luis</firstname>
+        <surname>Rodriguez</surname>
+        <affiliation>
+          <address><email>mcgrof@kernel.org</email></address>
+        </affiliation>
+      </author>
+    </authorgroup>
+
+    <legalnotice>
+      <para>
+        This documentation is free software; you can redistribute
+        it and/or modify it under the terms of the GNU General Public
+        License version 2 as published by the Free Software Foundation.
+      </para>
+      <para>
+        This documentation is distributed in the hope that it will be
+        useful, but WITHOUT ANY WARRANTY; without even the implied
+        warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+        See the GNU General Public License for more details.
+      </para>
+      <para>
+        You should have received a copy of the GNU General Public
+        License along with this documentation; if not, write to the Free
+        Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+        MA 02111-1307 USA
+      </para>
+      <para>
+        For more details see the file COPYING in the source
+        distribution of Linux.
+      </para>
+    </legalnotice>
+
+    <abstract>
+      <para>
+        This book documents the Linux' use of linker tables, how you can
+        use them and how they work.
+      </para>
+    </abstract>
+  </setinfo>
+  <book id="linux-linux-tables">
+    <bookinfo>
+      <title>Linux linker tables</title>
+
+      <abstract>
+!Pinclude/linux/tables.h Introduction
+      </abstract>
+    </bookinfo>
+
+      <chapter>
+      <title>About Linker tables</title>
+
+	<sect1>
+	<title>Linker table provenance and userspace testing</title>
+!Pinclude/linux/tables.h Linker table provenance and userspace testing
+	</sect1>
+
+	<sect1>
+	<title>The code bit-rot problem</title>
+!Pinclude/linux/tables.h The code bit-rot problem
+	</sect1>
+
+	<sect1>
+	<title>Avoiding the code bit-rot problem when desirable</title>
+!Pinclude/linux/tables.h Avoiding the code bit-rot problem when desirable
+	</sect1>
+      </chapter>
+
+      <chapter>
+      <title>Using linker tables in Linux</title>
+
+	<sect1>
+      <title>Using target table-y and table-n</title>
+!Pinclude/linux/tables.h Using target table-y and table-n
+	</sect1>
+
+	<sect1>
+	<title>Opting out of forcing compilation</title>
+!Pinclude/linux/tables.h Opting out of forcing compilation
+	</sect1>
+
+	<sect1>
+	<title>How linker tables simplify inits</title>
+!Pinclude/linux/tables.h How linker tables simplify inits
+	</sect1>
+
+      </chapter>
+
+      <chapter>
+      <title>Linker table helpers</title>
+!Pinclude/linux/tables.h Linker table helpers
+!Finclude/linux/tables.h LINKTABLE_ADDR_WITHIN
+      </chapter>
+
+      <chapter>
+      <title>Constructing Linker tables</title>
+!Pinclude/linux/tables.h Constructing linker tables
+
+	<sect1>
+	<title>Weak linker tables constructors</title>
+!Pinclude/linux/tables.h Weak linker tables constructors
+!Finclude/linux/tables.h LINKTABLE_WEAK
+!Finclude/linux/tables.h LINKTABLE_TEXT_WEAK
+!Finclude/linux/tables.h LINKTABLE_DATA_WEAK
+!Finclude/linux/tables.h LINKTABLE_RO_WEAK
+!Finclude/linux/tables.h LINKTABLE_INIT_WEAK
+!Finclude/linux/tables.h LINKTABLE_INIT_DATA_WEAK
+	</sect1>
+
+	<sect1>
+	<title>Regular linker linker table constructors</title>
+!Pinclude/linux/tables.h Regular linker linker table constructors
+!Finclude/linux/tables.h LINKTABLE_TEXT
+!Finclude/linux/tables.h LINKTABLE_DATA
+!Finclude/linux/tables.h LINKTABLE_RO
+!Finclude/linux/tables.h LINKTABLE_INIT
+!Finclude/linux/tables.h LINKTABLE_INIT_DATA
+	</sect1>
+      </chapter>
+
+      <chapter>
+      <title>Declaring Linker tables</title>
+!Pinclude/linux/tables.h Declaring Linker tables
+!Finclude/linux/tables.h DECLARE_LINKTABLE_TEXT
+!Finclude/linux/tables.h DECLARE_LINKTABLE_DATA
+!Finclude/linux/tables.h DECLARE_LINKTABLE_RO
+!Finclude/linux/tables.h DECLARE_LINKTABLE_INIT
+!Finclude/linux/tables.h DECLARE_LINKTABLE_INIT_DATA
+      </chapter>
+
+      <chapter>
+      <title>Defining Linker tables</title>
+!Pinclude/linux/tables.h Defining Linker tables
+!Finclude/linux/tables.h DEFINE_LINKTABLE_TEXT
+!Finclude/linux/tables.h DEFINE_LINKTABLE_DATA
+!Finclude/linux/tables.h DEFINE_LINKTABLE_RO
+!Finclude/linux/tables.h DEFINE_LINKTABLE_INIT
+!Finclude/linux/tables.h DEFINE_LINKTABLE_INIT_DATA
+      </chapter>
+
+      <chapter>
+      <title>Iterating over Linker tables</title>
+!Pinclude/linux/tables.h Iterating over Linker tables
+!Finclude/linux/tables.h LINKTABLE_FOR_EACH
+!Finclude/linux/tables.h LINKTABLE_RUN_ALL
+!Finclude/linux/tables.h LINKTABLE_RUN_ERR
+      </chapter>
+
+  </book>
+</set>
diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
index 385a5ef41c17..c63751312810 100644
--- a/Documentation/kbuild/makefiles.txt
+++ b/Documentation/kbuild/makefiles.txt
@@ -1089,6 +1089,25 @@ 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.
 
+    table-y table-m and table-
+
+	To avoid code bit-rot you may wish to avoid using #ifdefs on your
+	code. Bit-rot is possible if certain features may not be enabled
+	on certain build environments. The table-y, specifies targets which you
+	always wish to force compilation on, but wish to only enable linking in
+	if the feature is enabled, these are features taking advantage of
+	Linux's linker tables. For details on how to implement a feature using
+	linker tablesrefer to include/linux/tables.h. Use of table-m is not
+	yet supported.
+
+	Example:
+		table-$(CONFIG-FEATURE_FOO) += foo.o
+
+	An alternative to using table-y, is to use extra-y followed by the
+	respective obj-y:
+
+		extra-y += foo.o
+		obj-$(CONFIG-FEATURE_FOO) += foo.o
 
 --- 6.7 Commands useful for building a boot image
 
diff --git a/arch/alpha/include/asm/tables.h b/arch/alpha/include/asm/tables.h
new file mode 100644
index 000000000000..e53ee883330c
--- /dev/null
+++ b/arch/alpha/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ALPHA_TABLES_H
+#define _ASM_ALPHA_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_ALPHA_TABLES_H */
diff --git a/arch/arc/include/asm/tables.h b/arch/arc/include/asm/tables.h
new file mode 100644
index 000000000000..a02e790bcb14
--- /dev/null
+++ b/arch/arc/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARC_TABLES_H
+#define _ASM_ARC_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_ARC_TABLES_H */
diff --git a/arch/arm/include/asm/tables.h b/arch/arm/include/asm/tables.h
new file mode 100644
index 000000000000..96c1147fb766
--- /dev/null
+++ b/arch/arm/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARM_TABLES_H
+#define _ASM_ARM_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_ARM_TABLES_H */
diff --git a/arch/arm64/include/asm/tables.h b/arch/arm64/include/asm/tables.h
new file mode 100644
index 000000000000..d84a554ec6da
--- /dev/null
+++ b/arch/arm64/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARM64_TABLES_H
+#define _ASM_ARM64_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_ARM64_TABLES_H */
diff --git a/arch/avr32/include/asm/tables.h b/arch/avr32/include/asm/tables.h
new file mode 100644
index 000000000000..7ef914761c38
--- /dev/null
+++ b/arch/avr32/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_AVR32_TABLES_H
+#define _ASM_AVR32_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_AVR32_TABLES_H */
diff --git a/arch/blackfin/include/asm/tables.h b/arch/blackfin/include/asm/tables.h
new file mode 100644
index 000000000000..6e7445818a9c
--- /dev/null
+++ b/arch/blackfin/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_BLACKFIN_TABLES_H
+#define _ASM_BLACKFIN_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_BLACKFIN_TABLES_H */
diff --git a/arch/c6x/include/asm/tables.h b/arch/c6x/include/asm/tables.h
new file mode 100644
index 000000000000..209642925772
--- /dev/null
+++ b/arch/c6x/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_C6X_TABLES_H
+#define _ASM_C6X_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_C6X_TABLES_H */
diff --git a/arch/cris/include/asm/tables.h b/arch/cris/include/asm/tables.h
new file mode 100644
index 000000000000..17c0f04e7c27
--- /dev/null
+++ b/arch/cris/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_CRIS_TABLES_H
+#define _ASM_CRIS_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_CRIS_TABLES_H */
diff --git a/arch/frv/include/asm/tables.h b/arch/frv/include/asm/tables.h
new file mode 100644
index 000000000000..7a6c1f263a07
--- /dev/null
+++ b/arch/frv/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_FRV_TABLES_H
+#define _ASM_FRV_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_FRV_TABLES_H */
diff --git a/arch/h8300/include/asm/tables.h b/arch/h8300/include/asm/tables.h
new file mode 100644
index 000000000000..fc4297961bb7
--- /dev/null
+++ b/arch/h8300/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_H8300_TABLES_H
+#define _ASM_H8300_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_H8300_TABLES_H */
diff --git a/arch/hexagon/include/asm/tables.h b/arch/hexagon/include/asm/tables.h
new file mode 100644
index 000000000000..73475cc63c77
--- /dev/null
+++ b/arch/hexagon/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_HEXAGON_TABLES_H
+#define _ASM_HEXAGON_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_HEXAGON_TABLES_H */
diff --git a/arch/ia64/include/asm/tables.h b/arch/ia64/include/asm/tables.h
new file mode 100644
index 000000000000..4d7084cf0bd4
--- /dev/null
+++ b/arch/ia64/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_IA64_TABLES_H
+#define _ASM_IA64_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_IA64_TABLES_H */
diff --git a/arch/m32r/include/asm/tables.h b/arch/m32r/include/asm/tables.h
new file mode 100644
index 000000000000..6708322deba8
--- /dev/null
+++ b/arch/m32r/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_M32R_TABLES_H
+#define _ASM_M32R_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_M32R_TABLES_H */
diff --git a/arch/m68k/include/asm/tables.h b/arch/m68k/include/asm/tables.h
new file mode 100644
index 000000000000..1f6def4822ff
--- /dev/null
+++ b/arch/m68k/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_M68K_TABLES_H
+#define _ASM_M68K_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_M68K_TABLES_H */
diff --git a/arch/metag/include/asm/tables.h b/arch/metag/include/asm/tables.h
new file mode 100644
index 000000000000..594ee23ab968
--- /dev/null
+++ b/arch/metag/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_METAG_TABLES_H
+#define _ASM_METAG_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_METAG_TABLES_H */
diff --git a/arch/microblaze/include/asm/tables.h b/arch/microblaze/include/asm/tables.h
new file mode 100644
index 000000000000..f84bbfbdd63c
--- /dev/null
+++ b/arch/microblaze/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MICROBLAZE_TABLES_H
+#define _ASM_MICROBLAZE_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_MICROBLAZE_TABLES_H */
diff --git a/arch/mips/include/asm/tables.h b/arch/mips/include/asm/tables.h
new file mode 100644
index 000000000000..db5d62983667
--- /dev/null
+++ b/arch/mips/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MIPS_TABLES_H
+#define _ASM_MIPS_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_MIPS_TABLES_H */
diff --git a/arch/mn10300/include/asm/tables.h b/arch/mn10300/include/asm/tables.h
new file mode 100644
index 000000000000..b6d19fb66119
--- /dev/null
+++ b/arch/mn10300/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MN10300_TABLES_H
+#define _ASM_MN10300_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_MN10300_TABLES_H */
diff --git a/arch/nios2/include/asm/tables.h b/arch/nios2/include/asm/tables.h
new file mode 100644
index 000000000000..5dce7fc56bf7
--- /dev/null
+++ b/arch/nios2/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_NIOS2_TABLES_H
+#define _ASM_NIOS2_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_NIOS2_TABLES_H */
diff --git a/arch/openrisc/include/asm/tables.h b/arch/openrisc/include/asm/tables.h
new file mode 100644
index 000000000000..1b052c3b1816
--- /dev/null
+++ b/arch/openrisc/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_OPENRISC_TABLES_H
+#define _ASM_OPENRISC_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_OPENRISC_TABLES_H */
diff --git a/arch/parisc/include/asm/tables.h b/arch/parisc/include/asm/tables.h
new file mode 100644
index 000000000000..da60f2d9588d
--- /dev/null
+++ b/arch/parisc/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_PARISC_TABLES_H
+#define _ASM_PARISC_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_PARISC_TABLES_H */
diff --git a/arch/powerpc/include/asm/tables.h b/arch/powerpc/include/asm/tables.h
new file mode 100644
index 000000000000..1615f2edc4fc
--- /dev/null
+++ b/arch/powerpc/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_POWERPC_TABLES_H
+#define _ASM_POWERPC_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_POWERPC_TABLES_H */
diff --git a/arch/s390/include/asm/tables.h b/arch/s390/include/asm/tables.h
new file mode 100644
index 000000000000..c9615ed026b2
--- /dev/null
+++ b/arch/s390/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_S390_TABLES_H
+#define _ASM_S390_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_S390_TABLES_H */
diff --git a/arch/score/include/asm/tables.h b/arch/score/include/asm/tables.h
new file mode 100644
index 000000000000..7694b5bfca91
--- /dev/null
+++ b/arch/score/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SCORE_TABLES_H
+#define _ASM_SCORE_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_SCORE_TABLES_H */
diff --git a/arch/sh/include/asm/tables.h b/arch/sh/include/asm/tables.h
new file mode 100644
index 000000000000..7db4ffee4d7e
--- /dev/null
+++ b/arch/sh/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SH_TABLES_H
+#define _ASM_SH_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_SH_TABLES_H */
diff --git a/arch/sparc/include/asm/tables.h b/arch/sparc/include/asm/tables.h
new file mode 100644
index 000000000000..c540236bd9f5
--- /dev/null
+++ b/arch/sparc/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SPARC_TABLES_H
+#define _ASM_SPARC_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_SPARC_TABLES_H */
diff --git a/arch/tile/include/asm/tables.h b/arch/tile/include/asm/tables.h
new file mode 100644
index 000000000000..33168b49a295
--- /dev/null
+++ b/arch/tile/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_TILE_TABLES_H
+#define _ASM_TILE_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_TILE_TABLES_H */
diff --git a/arch/um/include/asm/tables.h b/arch/um/include/asm/tables.h
new file mode 100644
index 000000000000..ed093477c617
--- /dev/null
+++ b/arch/um/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_UM_TABLES_H
+#define _ASM_UM_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_UM_TABLES_H */
diff --git a/arch/unicore32/include/asm/tables.h b/arch/unicore32/include/asm/tables.h
new file mode 100644
index 000000000000..6edc65c625f5
--- /dev/null
+++ b/arch/unicore32/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_UNICORE32_TABLES_H
+#define _ASM_UNICORE32_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_UNICORE32_TABLES_H */
diff --git a/arch/x86/include/asm/tables.h b/arch/x86/include/asm/tables.h
new file mode 100644
index 000000000000..5828e3a73a61
--- /dev/null
+++ b/arch/x86/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_X86_TABLES_H
+#define _ASM_X86_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_X86_TABLES_H */
diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
index 0c2fae8d929d..07b335c67139 100644
--- a/arch/x86/tools/relocs.c
+++ b/arch/x86/tools/relocs.c
@@ -1,4 +1,5 @@
 /* This is included from relocs_32/64.c */
+#include <linux/sections.h>
 
 #define ElfW(type)		_ElfW(ELF_BITS, type)
 #define _ElfW(bits, type)	__ElfW(bits, type)
@@ -68,6 +69,8 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = {
 	"__end_rodata|"
 	"__initramfs_start|"
 	"(jiffies|jiffies_64)|"
+	SECTION_TBL_ALL_STR(SECTION_RODATA) "|"
+	SECTION_TBL_ALL_STR(SECTION_INIT) "|"
 #if ELF_BITS = 64
 	"__per_cpu_load|"
 	"init_per_cpu__.*|"
diff --git a/arch/xtensa/include/asm/tables.h b/arch/xtensa/include/asm/tables.h
new file mode 100644
index 000000000000..af78c7cd8e47
--- /dev/null
+++ b/arch/xtensa/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_XTENSA_TABLES_H
+#define _ASM_XTENSA_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_XTENSA_TABLES_H */
diff --git a/include/asm-generic/tables.h b/include/asm-generic/tables.h
new file mode 100644
index 000000000000..5cf655590a19
--- /dev/null
+++ b/include/asm-generic/tables.h
@@ -0,0 +1,70 @@
+#ifndef _ASM_GENERIC_TABLES_H_
+#define _ASM_GENERIC_TABLES_H_
+/*
+ * Linux linker tables
+ *
+ * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
+ *
+ * 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/.
+ */
+
+#ifdef __KERNEL__
+# include <asm/sections.h>
+#endif /* __KERNEL__ */
+
+#define SECTION_TYPE_TABLES	tbl
+
+#define SECTION_TBL(section, name, level)				\
+	SECTION_TYPE(section, SECTION_TYPE_TABLES, name, level)
+
+#define SECTION_TBL_ALL(section)					\
+	SECTION_TYPE_ALL(section,SECTION_TYPE_TABLES)
+
+#ifndef section_tbl
+# define section_tbl(section, name, level, flags)			\
+	 section_type(section, SECTION_TYPE_TABLES, name,		\
+		     level, flags)
+#endif
+
+#ifndef section_tbl_any
+# define section_tbl_any(section, name, flags)				\
+	 section_type(section, SECTION_TYPE_TABLES, name,		\
+		     SECTION_ORDER_ANY, flags)
+#endif
+
+#ifndef section_tbl_asmtype
+# define section_tbl_asmtype(section, name, level, flags, asmtype)	\
+	 section_type_asmtype(section, SECTION_TYPE_TABLES, name,	\
+			     level, flags, asmtype)
+#endif
+
+#ifndef push_section_tbl
+# define push_section_tbl(section, name, level, flags)			\
+	 push_section_type(section, SECTION_TYPE_TABLES, name,		\
+			  level, flags)
+#endif
+
+#ifndef push_section_tbl_any
+# define push_section_tbl_any(section, name, flags)			\
+	 push_section_type(section, SECTION_TYPE_TABLES, name,		\
+			  SECTION_ORDER_ANY, flags)
+#endif
+
+#if defined(__ASSEMBLER__) || defined(__ASSEMBLY__)
+
+# ifndef DECLARE_SECTION_TBL
+#  define DECLARE_SECTION_TBL(section, name)				\
+  push_section_tbl(section, name,,) ;					\
+  .globl name ;								\
+name: ;									\
+  .popsection								\
+									\
+  push_section_tbl(section, name, ~,) ;					\
+  .popsection
+# endif
+
+#endif /* defined(__ASSEMBLER__) || defined(__ASSEMBLY__) */
+
+#endif /* _ASM_GENERIC_TABLES_H_ */
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 0042f30ff34b..b3a9cd7bc947 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -56,6 +56,7 @@
 
 #include <linux/export.h>
 #include <asm/sections.h>
+#include <asm/tables.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_TBL_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_TBL_ALL(SECTION_RODATA)))		\
+		*(SECTION_ALL(SECTION_RODATA))				\
 		RO_AFTER_INIT_DATA	/* Read only after init */	\
 		*(__vermagic)		/* Kernel version magic */	\
 		. = ALIGN(8);						\
@@ -434,6 +438,7 @@
 #define TEXT_TEXT							\
 		ALIGN_FUNCTION();					\
 		*(.text.hot SECTION_TEXT .text.fixup .text.unlikely)	\
+		*(SORT(SECTION_TBL_ALL(SECTION_TEXT)))			\
 		*(SECTION_REF)						\
 	MEM_KEEP(init.text)						\
 	MEM_KEEP(exit.text)						\
@@ -529,6 +534,7 @@
 /* init and exit section handling */
 #define INIT_DATA							\
 	*(SECTION_INIT_DATA)						\
+	*(SORT(SECTION_TBL_ALL(SECTION_INIT_DATA)))			\
 	MEM_DISCARD(init.data)						\
 	KERNEL_CTORS()							\
 	MCOUNT_REC()							\
@@ -551,6 +557,7 @@
 
 #define INIT_TEXT							\
 	*(SECTION_INIT)							\
+	*(SORT(SECTION_TBL_ALL(SECTION_INIT)))				\
 	*(.text.startup)						\
 	MEM_DISCARD(init.text)
 
diff --git a/include/linux/tables.h b/include/linux/tables.h
new file mode 100644
index 000000000000..89d46f4c5739
--- /dev/null
+++ b/include/linux/tables.h
@@ -0,0 +1,597 @@
+#ifndef _LINUX_LINKER_TABLES_H
+#define _LINUX_LINKER_TABLES_H
+/*
+ * Linux linker tables
+ *
+ * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
+ *
+ * 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 <linux/sections.h>
+#ifdef __KERNEL__
+# include <asm/tables.h>
+#endif /* __KERNEL__ */
+
+#ifndef __ASSEMBLY__
+
+/**
+ * DOC: Introduction
+ *
+ * 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 linker table
+ * solution provides a general linker table facility so that a new linker table
+ * can be implemented by changing C code only.
+ *
+ * Linker tables help you simplify init sequences by using ELF sections, linker
+ * build time selective sorting (disabled options get ignored), and can
+ * optionally also be used to help you avoid code bit-rot due to #ifdery
+ * collateral.
+ */
+
+/**
+ * DOC: Linker table provenance and userspace testing
+ *
+ * The Linux implementation of linker tables is derivative of iPXE linker
+ * table's solution (iPXE commit 67a10ef000cb7 [0]).  To see how this code
+ * evolved or to extend and test and use this code in userspace refer to the
+ * userspace linker-table tree [1].  This repository can be used for ease of
+ * testing of extensions and sampling of changes prior to inclusion into Linux,
+ * it is intended to be kept up to date to match Linux's solution. Contrary to
+ * iPXE's solution, which strives to force compilation of everything using
+ * linker tables, Linux's solution allows for developers to be selective over
+ * where one wishes to force compilation, this then is just an optional feature
+ * for the Linux linker table solution.
+ *
+ * [0] git://git.ipxe.org/ipxe.git
+ *
+ * [1] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linker-tables.git/
+ */
+
+/**
+ * DOC: The code bit-rot problem
+ *
+ * Overuse of C #ifdefs can be problematic for certain types of code.  Linux
+ * provides a rich array of features, but all these features take up valuable
+ * space in a kernel image. The traditional solution to this problem has been
+ * for each feature to have its own Kconfig entry and for the respective code
+ * to be wrapped around #ifdefs, allowing the feature to be compiled in only
+ * if desired.
+ *
+ * The problem with this is that over time it becomes very difficult and time
+ * consuming to compile, let alone test, all possible versions of Linux. Code
+ * that is not typically used tends to suffer from bit-rot over time. It can
+ * become difficult to predict which combinations of compile-time options will
+ * result in code that can compile and link correctly.
+ */
+
+/**
+ * DOC: Avoiding the code bit-rot problem when desirable
+ *
+ * To solve the code bit-rot problem linker tables can be used on Linux, it
+ * enables you to always force compiling of select features that one wishes to
+ * avoid bit-rot while still enabling you to disable linking feature code into
+ * the final kernel image if the features have been disabled via Kconfig.
+ * Linux's linker tables allows for developers to be selective over where one
+ * wishes to take advantage of the optional feature of forcing compilation and
+ * only linking in enabled features.
+ *
+ * To use linker tables and to optionally take advantage of avoiding code
+ * bit-rot, feature code should be implemented in separate C files, and should
+ * be designed to always be compiled -- they should not be guarded with a C
+ * code #ifdef CONFIG_FOO statements, consideration must also be taken for
+ * sub-features which depend on the main CONFIG_FOO option, as they will be
+ * disabled if they depend on CONFIG_FOO and therefore not compiled. To force
+ * compilation and only link when features are needed a new optional target
+ * table-y can be used on Makefiles, documented below.
+ *
+ * Currently only built-in features are supported, modular support is not
+ * yet supported, however you can make use of sub-features for modules
+ * if they are independent and can simply be linked into modules.
+ */
+
+/**
+ * DOC: Using target table-y and table-n
+ *
+ * Let's assume we want to always force compilation of feature FOO in the
+ * kernel but avoid linking it. When you enable the FOO feature via Kconfig
+ * you'd end up with:
+ *
+ *	#define CONFIG_FOO 1
+ *
+ * You typically would then just use this on your Makefile to selectively
+ * compile and link the feature:
+ *
+ *	obj-$(CONFIG_FOO) += foo.o
+ *
+ * You could instead optionally use the new linker table object:
+ *
+ *	table-$(CONFIG_FOO) += foo.o
+ *
+ * Alternatively, this would be the equivalent of listing:
+ *
+ *	extra += foo.o
+ *	obj-$(CONFIG_FOO) += foo.o
+ *
+ * Both are mechanisms which can be used to take advantage of forcing
+ * compilation with linker tables, however making use of table-$(CONFIG_FOO)
+ * is encouraged as it helps with annotating linker tables clearly where
+ * compilation is forced.
+ */
+
+/**
+ * DOC: Opting out of forcing compilation
+ *
+ * If you want to opt-out of forcing compilation you would use the typical
+ * obj-$(CONFIG_FOO) += foo.o and foo.o will only be compiled and linked
+ * in when enabled. Using both table-$(CONFIG_FOO) and obj-($CONFIG_FOO)
+ * will result with the feature on your binary only if you've enabled
+ * CONFIG_FOO, however using table-$(CONFIG_FOO) will always force compilation,
+ * this is why avoiding code bit-rot is an optional fature for Linux linker
+ * tables.
+ */
+
+/**
+ * DOC: How linker tables simplify inits
+ *
+ * Traditionally, we would implement features in C code as follows:
+ *
+ *	foo_init();
+ *
+ * You'd then have a foo.h which would have:
+ *
+ *	#ifdef CONFIG_FOO
+ *	#else
+ *	static inline void foo(void) { }
+ *	#endif
+ *
+ * With linker tables this is no longer necessary as your init routines would
+ * be implicit, you'd instead call:
+ *
+ *	call_init_fns();
+ *
+ * call_init_fns() would call all functions present in your init table and if
+ * and only if foo.o gets linked in, then its initialisation function will be
+ * called, whether you use obj-$(CONFIG_FOO) or table-$(CONFIG_FOO).
+ *
+ * The linker script takes care of assembling the tables for us. All of our
+ * table sections have names of the format SECTION_NAME*.tbl.NAME.N. Here
+ * SECTION_NAME is one of the standard sections in include/linux/sections.h,
+ * and NAME designates the specific use case for the linker table, the table.
+ * N is a digit decimal number used to impose an "order level" upon the tables
+ * if required. NN= (empty string) is reserved for the symbol indicating "table
+ * start", and N=~ is reserved for the symbol indicating "table end". In order
+ * for the call_init_fns() to work behind the scenes the custom linker script
+ * would need to define the beginning of the table, the end of the table, and
+ * in between it should use SORT() to give order-level effect. Now, typically
+ * such type of requirements would require custom linker script modifications
+ * but Linux's linker tables builds on top of already existing standard Linux
+ * ELF sections, each with different purposes. This lets you build and add
+ * new tables without needing custom linker script modifications. This is
+ * also done to support all architectures. All that is needed then is to
+ * ensure a respective common linker table entry is added to the shared
+ * include/asm-generic/vmlinux.lds.h. There should be a respective:
+ *
+ *	*(SORT(SECTION_TBL_ALL(SECTION_NAME)))
+ *
+ * entry for each type of supported section there. If your SECTION_NAME
+ * is not yet supported, consider adding support for it.
+ *
+ * The order-level is really only a helper, if only one order level is
+ * used, the next contributing factor to order is the order of the code
+ * in the C file, and the order of the objects in the Makefile. Using
+ * an order level then should not really be needed in most cases, its
+ * use however enables to compartamentalize code into tables where ordering
+ * through C file or through the Makefile would otherwise be very difficult
+ * or if one wanted to enable very specific initialization semantics.
+ *
+ * As an example, suppose that we want to create a "frobnicator"
+ * feature framework, and allow for several independent modules to
+ * provide frobnicating services. Then we would create a frob.h
+ * header file containing e.g.
+ *
+ *	struct frobnicator {
+ *		const char *name;
+ *		void (*frob) (void);
+ *	};
+ *
+ *	DECLARE_LINKTABLE(struct frobnicator, frobnicator_fns);
+ *
+ * Any module providing frobnicating services would look something
+ * like
+ *
+ *	#include "frob.h"
+ *	static void my_frob(void) {
+ *		... Do my frobnicating
+ *	}
+ *	LINKTABLE_INIT_DATA(frobnicator_fns, all) my_frobnicator = {
+ *		.name = "my_frob",
+ *		.frob = my_frob,
+ *	};
+ *
+ * The central frobnicator code (frob.c) would use the frobnicating
+ * modules as follows
+ *
+ *	#include "frob.h"
+ *
+ *	void frob_all(void) {
+ *		struct frob *frob;
+ *
+ *		LINKTABLE_FOR_EACH(frob, frobnicator_fns) {
+ *			pr_info("Calling frobnicator \"%s\"\n", frob->name);
+ *			frob->frob();
+ *		}
+ *	}
+ */
+
+/**
+ * DOC: Linker table helpers
+ *
+ * These are helpers for linker tables.
+ */
+
+/**
+ * LINKTABLE_ADDR_WITHIN - returns true if address is in range
+ *
+ * @tbl: linker table
+ * @addr: address to query for
+ *
+ * Returns true if the address is part of the linker table.
+ */
+#define LINKTABLE_ADDR_WITHIN(tbl, addr)				\
+	 (addr >= (unsigned long) LINUX_SECTION_START(tbl) &&		\
+          addr < (unsigned long) LINUX_SECTION_END(tbl))
+
+/**
+ * DOC: Constructing linker tables
+ *
+ * Linker tables constructors are used to build an entry into a linker table.
+ * Linker table constructors exist for each type of supported section.
+ *
+ * You have weak and regular type of link table entry constructors.
+ */
+
+/**
+ * DOC: Weak linker tables constructors
+ *
+ * The weak attribute is desirable if you want an entry you can replace at
+ * link time. A very special use case for linker tables is the first entry.
+ * A weak attribute is used for the first entry to ensure that this entry's
+ * address matches the end address of the table when the linker table is
+ * emtpy, but will also point to the first real entry of the table once not
+ * empty. When the first entry is linked in, it takes place of the first entry.
+ */
+
+/**
+ * LINKTABLE_WEAK - Constructs a weak linker table entry for data
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Constructs a weak linker table for data.
+ */
+#define LINKTABLE_WEAK(name, level)					\
+	      __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     weak,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_DATA, name, level))))
+
+/**
+ * LINKTABLE_TEXT_WEAK - Constructs a weak linker table entry for execution
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Constructs a weak linker table for code execution. These will be
+ * read-only.
+ */
+#define LINKTABLE_TEXT_WEAK(name, level)				\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     weak,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_TEXT, name, level))))
+
+/**
+ * LINKTABLE_RO_WEAK - Constructs a weak read-only linker table entry
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Constructs a weak linker table which only requires read-only access.
+ */
+#define LINKTABLE_RO_WEAK(name, level)					\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     weak,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_RODATA, name, level))))
+
+/**
+ * LINKTABLE_INIT_WEAK - Constructs a weak linker table entry for init code
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Constructs a weak linker table for execution. use at init.
+ */
+#define LINKTABLE_INIT_WEAK(name, level)				\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     weak,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_INIT, name, level))))
+
+/**
+ * LINKTABLE_INIT_DATA_WEAK - Constructs a weak linker table entry for initdata
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Constructs a weak linker table for data during init.
+ */
+#define LINKTABLE_INIT_DATA_WEAK(name, level)				\
+	      __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     weak,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_INIT_DATA, name, level))))
+
+/**
+ * DOC: Regular linker linker table constructors
+ *
+ * Regular constructors are expected to be used for valid linker table entries.
+ * Valid uses of weak entries other than the beginning and is currently
+ * untested but should in theory work.
+ */
+
+/**
+ * LINKTABLE - Declares a data linker table entry
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Declares a data linker table entry. These are read-write.
+ */
+#define LINKTABLE(name, level)						\
+	      __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_DATA, name, level))))
+
+/**
+ * LINKTABLE_TEXT - Declares a linker table entry for execution
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Declares a linker table to be used for execution.
+ */
+#define LINKTABLE_TEXT(name, level)					\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_TEXT, name, level))))
+
+/**
+ * LINKTABLE_RO - Declares a read-only linker table entry.
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Declares a linker table which only requires read-only access.
+ */
+#define LINKTABLE_RO(name, level)					\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_RODATA, name, level))))
+
+/**
+ * LINKTABLE_INIT - Declares a linker table entry to be used on init.
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Declares a linker table entry for execution use during init.
+ */
+#define LINKTABLE_INIT(name, level)					\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     __aligned__(LINUX_SECTION_ALIGN_FUNC),	\
+			     section(SECTION_TBL(SECTION_INIT, name, level))))
+
+/**
+ * LINKTABLE_INIT_DATA - Declares a linker table entry to be used on init data.
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Declares a linker table entry for data during init.
+ */
+#define LINKTABLE_INIT_DATA(name, level)					\
+	      __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_INIT_DATA, name, level))))
+
+/**
+ * DOC: Declaring Linker tables
+ *
+ * Declarers are used to help code access the linker tables. Typically
+ * header files for subsystems would declare the linker tables to enable
+ * easy access to add new entries, and to iterate over the list of table.
+ */
+
+
+/**
+ * DECLARE_LINKTABLE - Declares a data linker table entry
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Declares a data linker table entry.
+ */
+#define DECLARE_LINKTABLE(type, name)					\
+	DECLARE_LINUX_SECTION(type, name)
+
+/**
+ * DECLARE_LINKTABLE_RO - Declares a read-only linker table entry
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Declares a read-only linker table entry.
+ */
+#define DECLARE_LINKTABLE_RO(type, name)				\
+	DECLARE_LINUX_SECTION_RO(type, name)
+
+/**
+ * DOC: Defining Linker tables
+ *
+ * Linker tables are defined in the code that takes ownership over
+ * the linker table. This is typically done in the same code that is in
+ * charge of iterating over the linker table as well.
+ */
+
+/**
+ * DEFINE_LINKTABLE - Defines a linker table for data
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Defines a linker table which used for data.
+ */
+#define DEFINE_LINKTABLE(type, name)					\
+	DECLARE_LINKTABLE(type, name);					\
+	LINKTABLE_WEAK(name, ) VMLINUX_SYMBOL(name)[0] = {};		\
+	LINKTABLE(name, ~) VMLINUX_SYMBOL(name##__end)[0] = {};
+
+/**
+ * DEFINE_LINKTABLE_TEXT - Declares linker table entry for exectuion
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Declares a linker table entry for execution.
+ */
+#define DEFINE_LINKTABLE_TEXT(type, name)				\
+	DECLARE_LINKTABLE_RO(type, name);				\
+	LINKTABLE_TEXT_WEAK(name, ) VMLINUX_SYMBOL(name)[0] = {};	\
+	LINKTABLE_TEXT(name, ~) VMLINUX_SYMBOL(name##__end)[0] = {};
+
+/**
+ * DEFINE_LINKTABLE_RO - Defines a read-only linker table
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Defines a linker table which we know only requires read-only access.
+ */
+#define DEFINE_LINKTABLE_RO(type, name)					\
+	DECLARE_LINKTABLE_RO(type, name);				\
+	LINKTABLE_RO_WEAK(name, ) VMLINUX_SYMBOL(name)[0] = {};		\
+	LINKTABLE_RO(name, ~) VMLINUX_SYMBOL(name##__end)[0] = {};
+
+/**
+ * DEFINE_LINKTABLE_INIT - Defines an init time linker table for execution
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Defines a linker table. If you are adding a new type you should
+ * enable CONFIG_DEBUG_SECTION_MISMATCH and ensure routines that make
+ * use of the linker tables get a respective __ref tag.
+ */
+#define DEFINE_LINKTABLE_INIT(type, name)				\
+	DECLARE_LINKTABLE(type, name);					\
+	LINKTABLE_INIT_WEAK(name, ) VMLINUX_SYMBOL(name)[0] = {};	\
+	LINKTABLE_INIT(name, ~) VMLINUX_SYMBOL(name##__end)[0] = {};
+
+/**
+ * DEFINE_LINKTABLE_INIT_DATA - Defines an init time linker table for data
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Defines a linker table for init data. If you are adding a new type you
+ * should enable CONFIG_DEBUG_SECTION_MISMATCH and ensure routines that make
+ * use of the linker tables get a respective __ref tag.
+ */
+#define DEFINE_LINKTABLE_INIT_DATA(type, name)				\
+	DECLARE_LINKTABLE(type, name);					\
+	LINKTABLE_INIT_DATA_WEAK(name, ) VMLINUX_SYMBOL(name)[0] = {};	\
+	LINKTABLE_INIT_DATA(name, ~) VMLINUX_SYMBOL(name##__end)[0] = {};
+
+/**
+ * DOC: Iterating over Linker tables
+ *
+ * To make use of the linker tables you want to be able to iterate over
+ * them. This section documents the different iterators available.
+ */
+
+/**
+ * LINKTABLE_FOR_EACH - iterate through all entries within a linker table
+ *
+ * @pointer: entry pointer
+ * @tbl: linker table
+ *
+ * Example usage:
+ *
+ *   struct frobnicator *frob;
+ *
+ *   LINKTABLE_FOR_EACH(frob, frobnicator_fns) {
+ *     ...
+ *   }
+ */
+
+#define LINKTABLE_FOR_EACH(pointer, tbl)				\
+	for (pointer = LINUX_SECTION_START(tbl);			\
+	     pointer < LINUX_SECTION_END(tbl);				\
+	     pointer++)
+
+/**
+ * LINKTABLE_RUN_ALL - iterate and run through all entries on a linker table
+ *
+ * @tbl: linker table
+ * @func: structure name for the function name we want to call.
+ * @args...: arguments to pass to func
+ *
+ * Example usage:
+ *
+ *   LINKTABLE_RUN_ALL(frobnicator_fns, some_run,);
+ */
+#define LINKTABLE_RUN_ALL(tbl, func, args...)				\
+do {									\
+	size_t i;							\
+	for (i = 0; i < LINUX_SECTION_SIZE(tbl); i++)			\
+		(tbl[i]).func (args);					\
+} while (0);
+
+/**
+ * LINKTABLE_RUN_ERR - run each linker table entry func and return error if any
+ *
+ * @tbl: linker table
+ * @func: structure name for the function name we want to call.
+ * @args...: arguments to pass to func
+ *
+ * Example usage:
+ *
+ *   unsigned int err = LINKTABLE_RUN_ERR(frobnicator_fns, some_run,);
+ */
+#define LINKTABLE_RUN_ERR(tbl, func, args...)				\
+({									\
+	size_t i;							\
+	int err = 0;							\
+	for (i = 0; !err && i < LINUX_SECTION_SIZE(tbl); i++)		\
+		err = (tbl[i]).func (args);				\
+		err; \
+})
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _LINUX_LINKER_TABLES_H */
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 11602e5efb3b..002857fe8d0d 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -91,7 +91,7 @@ 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) $(table-y)) \
 	 $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \
 	 $(subdir-ym) $(always)
 	@:
@@ -326,7 +326,7 @@ $(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 += $(extra-y) $(table-y) $(MAKECMDGOALS) $(always)
 
 # Linker scripts preprocessor (.lds.S -> .lds)
 # ---------------------------------------------------------------------------
diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
index 50616ea25131..bdc29810dae5 100644
--- a/scripts/Makefile.clean
+++ b/scripts/Makefile.clean
@@ -36,6 +36,7 @@ subdir-ymn	:= $(addprefix $(obj)/,$(subdir-ymn))
 # directory
 
 __clean-files	:= $(extra-y) $(extra-m) $(extra-)       \
+		   $(table-y) $(table-m) $(table-)       \
 		   $(always) $(targets) $(clean-files)   \
 		   $(host-progs)                         \
 		   $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 0a07f9014944..494f215ebaa4 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -12,6 +12,16 @@ export KBUILD_SUBDIR_CCFLAGS := $(KBUILD_SUBDIR_CCFLAGS) $(subdir-ccflags-y)
 # Figure out what we need to build from the various variables
 # ===================================== 
+# Linker tables objects always wish to be built to avoid bit-rot in
+# code, but only linked in *iff* they were enabled. We accomplish this
+# using pegging linker table objects into extra-y, which forces
+# compilation and then using the respective table-y and table-m as
+# as hints for things we do want enabled. Objects which we want to
+# avoid linking in will be in table-, not table-y and table-m.
+extra-y += $(table-)
+obj-m += $(table-m)
+obj-y += $(table-y)
+
 # When an object is listed to be built compiled-in and modular,
 # only build the compiled-in version
 
@@ -72,6 +82,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))
+table-y		:= $(addprefix $(obj)/,$(table-y))
+table-m		:= $(addprefix $(obj)/,$(table-m))
 always		:= $(addprefix $(obj)/,$(always))
 targets		:= $(addprefix $(obj)/,$(targets))
 modorder	:= $(addprefix $(obj)/,$(modorder))
diff --git a/tools/include/linux/sections.h b/tools/include/linux/sections.h
new file mode 100644
index 000000000000..cc6f07f11583
--- /dev/null
+++ b/tools/include/linux/sections.h
@@ -0,0 +1,13 @@
+#ifndef _TOOLS_LINUX_SECTIONS_H_
+
+/* Mostly a copy of what we need only */
+
+#define SECTION_INIT			.init.text
+#define SECTION_RODATA			.rodata
+
+#define ___SECTION_TBL_STR(section, name)				\
+	#section ".tbl." #name
+#define SECTION_TBL_ALL_STR(section)					\
+	___SECTION_TBL_STR(section, *)
+
+#endif /* _TOOLS_LINUX_SECTIONS_H_ */
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 07/13] tables.h: add linker table support
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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
originally based on Michael Brown's iPXE's linker table solution but
has been significantly modified to fit Linux's use in its integration.

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.

Bit rotting avoidance is enabled by *granting the option* to force
compilation of code and only enable linking object code in when
specific features have been enabled. It accomplishes this by using
linker sections, the lightweight feature ordering of code is enabled
by taking advantage of the old binutils ld SORT() on features
specific sections.

Contrary to iPXE's solution, which strives to force compilation
of all features, Linux' solution strives to encourage usage of linker
tables to force compilation of code *only on designated code*. Linker
tables can be used without requiring one to force code compilation
of features that use it though, to take advantage of the simplification
of init sequences.

Linux code that uses linker tables *and* wishes to always require
compilation but selectively linking must use new kbuild target object
that helps accomplishes this, table-y. Linux code that uses linker
tables but does not want to require forcing compilation can use the
good 'ol obj-y targets.

Used commit 67a10ef000cb7 from iPXE upstream [0] as the starting point
for development and evaluation of Linux's integration, further changes
made and evaluation of different linker table options for Linux are
available on the linker-table userspace tree [1].

[0] git://git.ipxe.org/ipxe.git
[1] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linker-tables.git/

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.

Cc: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 Documentation/DocBook/Makefile           |   2 +-
 Documentation/DocBook/linker-tables.tmpl | 166 +++++++++
 Documentation/kbuild/makefiles.txt       |  19 +
 arch/alpha/include/asm/tables.h          |   6 +
 arch/arc/include/asm/tables.h            |   6 +
 arch/arm/include/asm/tables.h            |   6 +
 arch/arm64/include/asm/tables.h          |   6 +
 arch/avr32/include/asm/tables.h          |   6 +
 arch/blackfin/include/asm/tables.h       |   6 +
 arch/c6x/include/asm/tables.h            |   6 +
 arch/cris/include/asm/tables.h           |   6 +
 arch/frv/include/asm/tables.h            |   6 +
 arch/h8300/include/asm/tables.h          |   6 +
 arch/hexagon/include/asm/tables.h        |   6 +
 arch/ia64/include/asm/tables.h           |   6 +
 arch/m32r/include/asm/tables.h           |   6 +
 arch/m68k/include/asm/tables.h           |   6 +
 arch/metag/include/asm/tables.h          |   6 +
 arch/microblaze/include/asm/tables.h     |   6 +
 arch/mips/include/asm/tables.h           |   6 +
 arch/mn10300/include/asm/tables.h        |   6 +
 arch/nios2/include/asm/tables.h          |   6 +
 arch/openrisc/include/asm/tables.h       |   6 +
 arch/parisc/include/asm/tables.h         |   6 +
 arch/powerpc/include/asm/tables.h        |   6 +
 arch/s390/include/asm/tables.h           |   6 +
 arch/score/include/asm/tables.h          |   6 +
 arch/sh/include/asm/tables.h             |   6 +
 arch/sparc/include/asm/tables.h          |   6 +
 arch/tile/include/asm/tables.h           |   6 +
 arch/um/include/asm/tables.h             |   6 +
 arch/unicore32/include/asm/tables.h      |   6 +
 arch/x86/include/asm/tables.h            |   6 +
 arch/x86/tools/relocs.c                  |   3 +
 arch/xtensa/include/asm/tables.h         |   6 +
 include/asm-generic/tables.h             |  70 ++++
 include/asm-generic/vmlinux.lds.h        |   9 +-
 include/linux/tables.h                   | 597 +++++++++++++++++++++++++++++++
 scripts/Makefile.build                   |   4 +-
 scripts/Makefile.clean                   |   1 +
 scripts/Makefile.lib                     |  12 +
 tools/include/linux/sections.h           |  13 +
 42 files changed, 1078 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/DocBook/linker-tables.tmpl
 create mode 100644 arch/alpha/include/asm/tables.h
 create mode 100644 arch/arc/include/asm/tables.h
 create mode 100644 arch/arm/include/asm/tables.h
 create mode 100644 arch/arm64/include/asm/tables.h
 create mode 100644 arch/avr32/include/asm/tables.h
 create mode 100644 arch/blackfin/include/asm/tables.h
 create mode 100644 arch/c6x/include/asm/tables.h
 create mode 100644 arch/cris/include/asm/tables.h
 create mode 100644 arch/frv/include/asm/tables.h
 create mode 100644 arch/h8300/include/asm/tables.h
 create mode 100644 arch/hexagon/include/asm/tables.h
 create mode 100644 arch/ia64/include/asm/tables.h
 create mode 100644 arch/m32r/include/asm/tables.h
 create mode 100644 arch/m68k/include/asm/tables.h
 create mode 100644 arch/metag/include/asm/tables.h
 create mode 100644 arch/microblaze/include/asm/tables.h
 create mode 100644 arch/mips/include/asm/tables.h
 create mode 100644 arch/mn10300/include/asm/tables.h
 create mode 100644 arch/nios2/include/asm/tables.h
 create mode 100644 arch/openrisc/include/asm/tables.h
 create mode 100644 arch/parisc/include/asm/tables.h
 create mode 100644 arch/powerpc/include/asm/tables.h
 create mode 100644 arch/s390/include/asm/tables.h
 create mode 100644 arch/score/include/asm/tables.h
 create mode 100644 arch/sh/include/asm/tables.h
 create mode 100644 arch/sparc/include/asm/tables.h
 create mode 100644 arch/tile/include/asm/tables.h
 create mode 100644 arch/um/include/asm/tables.h
 create mode 100644 arch/unicore32/include/asm/tables.h
 create mode 100644 arch/x86/include/asm/tables.h
 create mode 100644 arch/xtensa/include/asm/tables.h
 create mode 100644 include/asm-generic/tables.h
 create mode 100644 include/linux/tables.h
 create mode 100644 tools/include/linux/sections.h

diff --git a/Documentation/DocBook/Makefile b/Documentation/DocBook/Makefile
index 1b2ac4731418..b78365cc3cd1 100644
--- a/Documentation/DocBook/Makefile
+++ b/Documentation/DocBook/Makefile
@@ -18,7 +18,7 @@ DOCBOOKS := z8530book.xml device-drivers.xml \
 	    alsa-driver-api.xml writing-an-alsa-driver.xml \
 	    tracepoint.xml media_api.xml w1.xml \
 	    writing_musb_glue_layer.xml crypto-API.xml iio.xml \
-	    sections.xml
+	    sections.xml linker-tables.xml
 
 include Documentation/DocBook/media/Makefile
 
diff --git a/Documentation/DocBook/linker-tables.tmpl b/Documentation/DocBook/linker-tables.tmpl
new file mode 100644
index 000000000000..fba90c61eee1
--- /dev/null
+++ b/Documentation/DocBook/linker-tables.tmpl
@@ -0,0 +1,166 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+	"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
+<set>
+  <setinfo>
+    <title>Linux linker tables</title>
+    <subtitle>
+      Explains Linux' linker tables work.
+    </subtitle>
+
+    <copyright>
+      <year>2015-2016</year>
+      <holder>Luis R. Rodriguez</holder>
+    </copyright>
+
+    <authorgroup>
+      <author>
+        <firstname>Luis</firstname>
+        <surname>Rodriguez</surname>
+        <affiliation>
+          <address><email>mcgrof@kernel.org</email></address>
+        </affiliation>
+      </author>
+    </authorgroup>
+
+    <legalnotice>
+      <para>
+        This documentation is free software; you can redistribute
+        it and/or modify it under the terms of the GNU General Public
+        License version 2 as published by the Free Software Foundation.
+      </para>
+      <para>
+        This documentation is distributed in the hope that it will be
+        useful, but WITHOUT ANY WARRANTY; without even the implied
+        warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+        See the GNU General Public License for more details.
+      </para>
+      <para>
+        You should have received a copy of the GNU General Public
+        License along with this documentation; if not, write to the Free
+        Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+        MA 02111-1307 USA
+      </para>
+      <para>
+        For more details see the file COPYING in the source
+        distribution of Linux.
+      </para>
+    </legalnotice>
+
+    <abstract>
+      <para>
+        This book documents the Linux' use of linker tables, how you can
+        use them and how they work.
+      </para>
+    </abstract>
+  </setinfo>
+  <book id="linux-linux-tables">
+    <bookinfo>
+      <title>Linux linker tables</title>
+
+      <abstract>
+!Pinclude/linux/tables.h Introduction
+      </abstract>
+    </bookinfo>
+
+      <chapter>
+      <title>About Linker tables</title>
+
+	<sect1>
+	<title>Linker table provenance and userspace testing</title>
+!Pinclude/linux/tables.h Linker table provenance and userspace testing
+	</sect1>
+
+	<sect1>
+	<title>The code bit-rot problem</title>
+!Pinclude/linux/tables.h The code bit-rot problem
+	</sect1>
+
+	<sect1>
+	<title>Avoiding the code bit-rot problem when desirable</title>
+!Pinclude/linux/tables.h Avoiding the code bit-rot problem when desirable
+	</sect1>
+      </chapter>
+
+      <chapter>
+      <title>Using linker tables in Linux</title>
+
+	<sect1>
+      <title>Using target table-y and table-n</title>
+!Pinclude/linux/tables.h Using target table-y and table-n
+	</sect1>
+
+	<sect1>
+	<title>Opting out of forcing compilation</title>
+!Pinclude/linux/tables.h Opting out of forcing compilation
+	</sect1>
+
+	<sect1>
+	<title>How linker tables simplify inits</title>
+!Pinclude/linux/tables.h How linker tables simplify inits
+	</sect1>
+
+      </chapter>
+
+      <chapter>
+      <title>Linker table helpers</title>
+!Pinclude/linux/tables.h Linker table helpers
+!Finclude/linux/tables.h LINKTABLE_ADDR_WITHIN
+      </chapter>
+
+      <chapter>
+      <title>Constructing Linker tables</title>
+!Pinclude/linux/tables.h Constructing linker tables
+
+	<sect1>
+	<title>Weak linker tables constructors</title>
+!Pinclude/linux/tables.h Weak linker tables constructors
+!Finclude/linux/tables.h LINKTABLE_WEAK
+!Finclude/linux/tables.h LINKTABLE_TEXT_WEAK
+!Finclude/linux/tables.h LINKTABLE_DATA_WEAK
+!Finclude/linux/tables.h LINKTABLE_RO_WEAK
+!Finclude/linux/tables.h LINKTABLE_INIT_WEAK
+!Finclude/linux/tables.h LINKTABLE_INIT_DATA_WEAK
+	</sect1>
+
+	<sect1>
+	<title>Regular linker linker table constructors</title>
+!Pinclude/linux/tables.h Regular linker linker table constructors
+!Finclude/linux/tables.h LINKTABLE_TEXT
+!Finclude/linux/tables.h LINKTABLE_DATA
+!Finclude/linux/tables.h LINKTABLE_RO
+!Finclude/linux/tables.h LINKTABLE_INIT
+!Finclude/linux/tables.h LINKTABLE_INIT_DATA
+	</sect1>
+      </chapter>
+
+      <chapter>
+      <title>Declaring Linker tables</title>
+!Pinclude/linux/tables.h Declaring Linker tables
+!Finclude/linux/tables.h DECLARE_LINKTABLE_TEXT
+!Finclude/linux/tables.h DECLARE_LINKTABLE_DATA
+!Finclude/linux/tables.h DECLARE_LINKTABLE_RO
+!Finclude/linux/tables.h DECLARE_LINKTABLE_INIT
+!Finclude/linux/tables.h DECLARE_LINKTABLE_INIT_DATA
+      </chapter>
+
+      <chapter>
+      <title>Defining Linker tables</title>
+!Pinclude/linux/tables.h Defining Linker tables
+!Finclude/linux/tables.h DEFINE_LINKTABLE_TEXT
+!Finclude/linux/tables.h DEFINE_LINKTABLE_DATA
+!Finclude/linux/tables.h DEFINE_LINKTABLE_RO
+!Finclude/linux/tables.h DEFINE_LINKTABLE_INIT
+!Finclude/linux/tables.h DEFINE_LINKTABLE_INIT_DATA
+      </chapter>
+
+      <chapter>
+      <title>Iterating over Linker tables</title>
+!Pinclude/linux/tables.h Iterating over Linker tables
+!Finclude/linux/tables.h LINKTABLE_FOR_EACH
+!Finclude/linux/tables.h LINKTABLE_RUN_ALL
+!Finclude/linux/tables.h LINKTABLE_RUN_ERR
+      </chapter>
+
+  </book>
+</set>
diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
index 385a5ef41c17..c63751312810 100644
--- a/Documentation/kbuild/makefiles.txt
+++ b/Documentation/kbuild/makefiles.txt
@@ -1089,6 +1089,25 @@ 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.
 
+    table-y table-m and table-
+
+	To avoid code bit-rot you may wish to avoid using #ifdefs on your
+	code. Bit-rot is possible if certain features may not be enabled
+	on certain build environments. The table-y, specifies targets which you
+	always wish to force compilation on, but wish to only enable linking in
+	if the feature is enabled, these are features taking advantage of
+	Linux's linker tables. For details on how to implement a feature using
+	linker tablesrefer to include/linux/tables.h. Use of table-m is not
+	yet supported.
+
+	Example:
+		table-$(CONFIG-FEATURE_FOO) += foo.o
+
+	An alternative to using table-y, is to use extra-y followed by the
+	respective obj-y:
+
+		extra-y += foo.o
+		obj-$(CONFIG-FEATURE_FOO) += foo.o
 
 --- 6.7 Commands useful for building a boot image
 
diff --git a/arch/alpha/include/asm/tables.h b/arch/alpha/include/asm/tables.h
new file mode 100644
index 000000000000..e53ee883330c
--- /dev/null
+++ b/arch/alpha/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ALPHA_TABLES_H
+#define _ASM_ALPHA_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_ALPHA_TABLES_H */
diff --git a/arch/arc/include/asm/tables.h b/arch/arc/include/asm/tables.h
new file mode 100644
index 000000000000..a02e790bcb14
--- /dev/null
+++ b/arch/arc/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARC_TABLES_H
+#define _ASM_ARC_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_ARC_TABLES_H */
diff --git a/arch/arm/include/asm/tables.h b/arch/arm/include/asm/tables.h
new file mode 100644
index 000000000000..96c1147fb766
--- /dev/null
+++ b/arch/arm/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARM_TABLES_H
+#define _ASM_ARM_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_ARM_TABLES_H */
diff --git a/arch/arm64/include/asm/tables.h b/arch/arm64/include/asm/tables.h
new file mode 100644
index 000000000000..d84a554ec6da
--- /dev/null
+++ b/arch/arm64/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARM64_TABLES_H
+#define _ASM_ARM64_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_ARM64_TABLES_H */
diff --git a/arch/avr32/include/asm/tables.h b/arch/avr32/include/asm/tables.h
new file mode 100644
index 000000000000..7ef914761c38
--- /dev/null
+++ b/arch/avr32/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_AVR32_TABLES_H
+#define _ASM_AVR32_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_AVR32_TABLES_H */
diff --git a/arch/blackfin/include/asm/tables.h b/arch/blackfin/include/asm/tables.h
new file mode 100644
index 000000000000..6e7445818a9c
--- /dev/null
+++ b/arch/blackfin/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_BLACKFIN_TABLES_H
+#define _ASM_BLACKFIN_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_BLACKFIN_TABLES_H */
diff --git a/arch/c6x/include/asm/tables.h b/arch/c6x/include/asm/tables.h
new file mode 100644
index 000000000000..209642925772
--- /dev/null
+++ b/arch/c6x/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_C6X_TABLES_H
+#define _ASM_C6X_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_C6X_TABLES_H */
diff --git a/arch/cris/include/asm/tables.h b/arch/cris/include/asm/tables.h
new file mode 100644
index 000000000000..17c0f04e7c27
--- /dev/null
+++ b/arch/cris/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_CRIS_TABLES_H
+#define _ASM_CRIS_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_CRIS_TABLES_H */
diff --git a/arch/frv/include/asm/tables.h b/arch/frv/include/asm/tables.h
new file mode 100644
index 000000000000..7a6c1f263a07
--- /dev/null
+++ b/arch/frv/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_FRV_TABLES_H
+#define _ASM_FRV_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_FRV_TABLES_H */
diff --git a/arch/h8300/include/asm/tables.h b/arch/h8300/include/asm/tables.h
new file mode 100644
index 000000000000..fc4297961bb7
--- /dev/null
+++ b/arch/h8300/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_H8300_TABLES_H
+#define _ASM_H8300_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_H8300_TABLES_H */
diff --git a/arch/hexagon/include/asm/tables.h b/arch/hexagon/include/asm/tables.h
new file mode 100644
index 000000000000..73475cc63c77
--- /dev/null
+++ b/arch/hexagon/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_HEXAGON_TABLES_H
+#define _ASM_HEXAGON_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_HEXAGON_TABLES_H */
diff --git a/arch/ia64/include/asm/tables.h b/arch/ia64/include/asm/tables.h
new file mode 100644
index 000000000000..4d7084cf0bd4
--- /dev/null
+++ b/arch/ia64/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_IA64_TABLES_H
+#define _ASM_IA64_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_IA64_TABLES_H */
diff --git a/arch/m32r/include/asm/tables.h b/arch/m32r/include/asm/tables.h
new file mode 100644
index 000000000000..6708322deba8
--- /dev/null
+++ b/arch/m32r/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_M32R_TABLES_H
+#define _ASM_M32R_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_M32R_TABLES_H */
diff --git a/arch/m68k/include/asm/tables.h b/arch/m68k/include/asm/tables.h
new file mode 100644
index 000000000000..1f6def4822ff
--- /dev/null
+++ b/arch/m68k/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_M68K_TABLES_H
+#define _ASM_M68K_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_M68K_TABLES_H */
diff --git a/arch/metag/include/asm/tables.h b/arch/metag/include/asm/tables.h
new file mode 100644
index 000000000000..594ee23ab968
--- /dev/null
+++ b/arch/metag/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_METAG_TABLES_H
+#define _ASM_METAG_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_METAG_TABLES_H */
diff --git a/arch/microblaze/include/asm/tables.h b/arch/microblaze/include/asm/tables.h
new file mode 100644
index 000000000000..f84bbfbdd63c
--- /dev/null
+++ b/arch/microblaze/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MICROBLAZE_TABLES_H
+#define _ASM_MICROBLAZE_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_MICROBLAZE_TABLES_H */
diff --git a/arch/mips/include/asm/tables.h b/arch/mips/include/asm/tables.h
new file mode 100644
index 000000000000..db5d62983667
--- /dev/null
+++ b/arch/mips/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MIPS_TABLES_H
+#define _ASM_MIPS_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_MIPS_TABLES_H */
diff --git a/arch/mn10300/include/asm/tables.h b/arch/mn10300/include/asm/tables.h
new file mode 100644
index 000000000000..b6d19fb66119
--- /dev/null
+++ b/arch/mn10300/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MN10300_TABLES_H
+#define _ASM_MN10300_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_MN10300_TABLES_H */
diff --git a/arch/nios2/include/asm/tables.h b/arch/nios2/include/asm/tables.h
new file mode 100644
index 000000000000..5dce7fc56bf7
--- /dev/null
+++ b/arch/nios2/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_NIOS2_TABLES_H
+#define _ASM_NIOS2_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_NIOS2_TABLES_H */
diff --git a/arch/openrisc/include/asm/tables.h b/arch/openrisc/include/asm/tables.h
new file mode 100644
index 000000000000..1b052c3b1816
--- /dev/null
+++ b/arch/openrisc/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_OPENRISC_TABLES_H
+#define _ASM_OPENRISC_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_OPENRISC_TABLES_H */
diff --git a/arch/parisc/include/asm/tables.h b/arch/parisc/include/asm/tables.h
new file mode 100644
index 000000000000..da60f2d9588d
--- /dev/null
+++ b/arch/parisc/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_PARISC_TABLES_H
+#define _ASM_PARISC_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_PARISC_TABLES_H */
diff --git a/arch/powerpc/include/asm/tables.h b/arch/powerpc/include/asm/tables.h
new file mode 100644
index 000000000000..1615f2edc4fc
--- /dev/null
+++ b/arch/powerpc/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_POWERPC_TABLES_H
+#define _ASM_POWERPC_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_POWERPC_TABLES_H */
diff --git a/arch/s390/include/asm/tables.h b/arch/s390/include/asm/tables.h
new file mode 100644
index 000000000000..c9615ed026b2
--- /dev/null
+++ b/arch/s390/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_S390_TABLES_H
+#define _ASM_S390_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_S390_TABLES_H */
diff --git a/arch/score/include/asm/tables.h b/arch/score/include/asm/tables.h
new file mode 100644
index 000000000000..7694b5bfca91
--- /dev/null
+++ b/arch/score/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SCORE_TABLES_H
+#define _ASM_SCORE_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_SCORE_TABLES_H */
diff --git a/arch/sh/include/asm/tables.h b/arch/sh/include/asm/tables.h
new file mode 100644
index 000000000000..7db4ffee4d7e
--- /dev/null
+++ b/arch/sh/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SH_TABLES_H
+#define _ASM_SH_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_SH_TABLES_H */
diff --git a/arch/sparc/include/asm/tables.h b/arch/sparc/include/asm/tables.h
new file mode 100644
index 000000000000..c540236bd9f5
--- /dev/null
+++ b/arch/sparc/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SPARC_TABLES_H
+#define _ASM_SPARC_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_SPARC_TABLES_H */
diff --git a/arch/tile/include/asm/tables.h b/arch/tile/include/asm/tables.h
new file mode 100644
index 000000000000..33168b49a295
--- /dev/null
+++ b/arch/tile/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_TILE_TABLES_H
+#define _ASM_TILE_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_TILE_TABLES_H */
diff --git a/arch/um/include/asm/tables.h b/arch/um/include/asm/tables.h
new file mode 100644
index 000000000000..ed093477c617
--- /dev/null
+++ b/arch/um/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_UM_TABLES_H
+#define _ASM_UM_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_UM_TABLES_H */
diff --git a/arch/unicore32/include/asm/tables.h b/arch/unicore32/include/asm/tables.h
new file mode 100644
index 000000000000..6edc65c625f5
--- /dev/null
+++ b/arch/unicore32/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_UNICORE32_TABLES_H
+#define _ASM_UNICORE32_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_UNICORE32_TABLES_H */
diff --git a/arch/x86/include/asm/tables.h b/arch/x86/include/asm/tables.h
new file mode 100644
index 000000000000..5828e3a73a61
--- /dev/null
+++ b/arch/x86/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_X86_TABLES_H
+#define _ASM_X86_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_X86_TABLES_H */
diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
index 0c2fae8d929d..07b335c67139 100644
--- a/arch/x86/tools/relocs.c
+++ b/arch/x86/tools/relocs.c
@@ -1,4 +1,5 @@
 /* This is included from relocs_32/64.c */
+#include <linux/sections.h>
 
 #define ElfW(type)		_ElfW(ELF_BITS, type)
 #define _ElfW(bits, type)	__ElfW(bits, type)
@@ -68,6 +69,8 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = {
 	"__end_rodata|"
 	"__initramfs_start|"
 	"(jiffies|jiffies_64)|"
+	SECTION_TBL_ALL_STR(SECTION_RODATA) "|"
+	SECTION_TBL_ALL_STR(SECTION_INIT) "|"
 #if ELF_BITS == 64
 	"__per_cpu_load|"
 	"init_per_cpu__.*|"
diff --git a/arch/xtensa/include/asm/tables.h b/arch/xtensa/include/asm/tables.h
new file mode 100644
index 000000000000..af78c7cd8e47
--- /dev/null
+++ b/arch/xtensa/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_XTENSA_TABLES_H
+#define _ASM_XTENSA_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_XTENSA_TABLES_H */
diff --git a/include/asm-generic/tables.h b/include/asm-generic/tables.h
new file mode 100644
index 000000000000..5cf655590a19
--- /dev/null
+++ b/include/asm-generic/tables.h
@@ -0,0 +1,70 @@
+#ifndef _ASM_GENERIC_TABLES_H_
+#define _ASM_GENERIC_TABLES_H_
+/*
+ * Linux linker tables
+ *
+ * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
+ *
+ * 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/.
+ */
+
+#ifdef __KERNEL__
+# include <asm/sections.h>
+#endif /* __KERNEL__ */
+
+#define SECTION_TYPE_TABLES	tbl
+
+#define SECTION_TBL(section, name, level)				\
+	SECTION_TYPE(section, SECTION_TYPE_TABLES, name, level)
+
+#define SECTION_TBL_ALL(section)					\
+	SECTION_TYPE_ALL(section,SECTION_TYPE_TABLES)
+
+#ifndef section_tbl
+# define section_tbl(section, name, level, flags)			\
+	 section_type(section, SECTION_TYPE_TABLES, name,		\
+		     level, flags)
+#endif
+
+#ifndef section_tbl_any
+# define section_tbl_any(section, name, flags)				\
+	 section_type(section, SECTION_TYPE_TABLES, name,		\
+		     SECTION_ORDER_ANY, flags)
+#endif
+
+#ifndef section_tbl_asmtype
+# define section_tbl_asmtype(section, name, level, flags, asmtype)	\
+	 section_type_asmtype(section, SECTION_TYPE_TABLES, name,	\
+			     level, flags, asmtype)
+#endif
+
+#ifndef push_section_tbl
+# define push_section_tbl(section, name, level, flags)			\
+	 push_section_type(section, SECTION_TYPE_TABLES, name,		\
+			  level, flags)
+#endif
+
+#ifndef push_section_tbl_any
+# define push_section_tbl_any(section, name, flags)			\
+	 push_section_type(section, SECTION_TYPE_TABLES, name,		\
+			  SECTION_ORDER_ANY, flags)
+#endif
+
+#if defined(__ASSEMBLER__) || defined(__ASSEMBLY__)
+
+# ifndef DECLARE_SECTION_TBL
+#  define DECLARE_SECTION_TBL(section, name)				\
+  push_section_tbl(section, name,,) ;					\
+  .globl name ;								\
+name: ;									\
+  .popsection								\
+									\
+  push_section_tbl(section, name, ~,) ;					\
+  .popsection
+# endif
+
+#endif /* defined(__ASSEMBLER__) || defined(__ASSEMBLY__) */
+
+#endif /* _ASM_GENERIC_TABLES_H_ */
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 0042f30ff34b..b3a9cd7bc947 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -56,6 +56,7 @@
 
 #include <linux/export.h>
 #include <asm/sections.h>
+#include <asm/tables.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_TBL_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_TBL_ALL(SECTION_RODATA)))		\
+		*(SECTION_ALL(SECTION_RODATA))				\
 		RO_AFTER_INIT_DATA	/* Read only after init */	\
 		*(__vermagic)		/* Kernel version magic */	\
 		. = ALIGN(8);						\
@@ -434,6 +438,7 @@
 #define TEXT_TEXT							\
 		ALIGN_FUNCTION();					\
 		*(.text.hot SECTION_TEXT .text.fixup .text.unlikely)	\
+		*(SORT(SECTION_TBL_ALL(SECTION_TEXT)))			\
 		*(SECTION_REF)						\
 	MEM_KEEP(init.text)						\
 	MEM_KEEP(exit.text)						\
@@ -529,6 +534,7 @@
 /* init and exit section handling */
 #define INIT_DATA							\
 	*(SECTION_INIT_DATA)						\
+	*(SORT(SECTION_TBL_ALL(SECTION_INIT_DATA)))			\
 	MEM_DISCARD(init.data)						\
 	KERNEL_CTORS()							\
 	MCOUNT_REC()							\
@@ -551,6 +557,7 @@
 
 #define INIT_TEXT							\
 	*(SECTION_INIT)							\
+	*(SORT(SECTION_TBL_ALL(SECTION_INIT)))				\
 	*(.text.startup)						\
 	MEM_DISCARD(init.text)
 
diff --git a/include/linux/tables.h b/include/linux/tables.h
new file mode 100644
index 000000000000..89d46f4c5739
--- /dev/null
+++ b/include/linux/tables.h
@@ -0,0 +1,597 @@
+#ifndef _LINUX_LINKER_TABLES_H
+#define _LINUX_LINKER_TABLES_H
+/*
+ * Linux linker tables
+ *
+ * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
+ *
+ * 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 <linux/sections.h>
+#ifdef __KERNEL__
+# include <asm/tables.h>
+#endif /* __KERNEL__ */
+
+#ifndef __ASSEMBLY__
+
+/**
+ * DOC: Introduction
+ *
+ * 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 linker table
+ * solution provides a general linker table facility so that a new linker table
+ * can be implemented by changing C code only.
+ *
+ * Linker tables help you simplify init sequences by using ELF sections, linker
+ * build time selective sorting (disabled options get ignored), and can
+ * optionally also be used to help you avoid code bit-rot due to #ifdery
+ * collateral.
+ */
+
+/**
+ * DOC: Linker table provenance and userspace testing
+ *
+ * The Linux implementation of linker tables is derivative of iPXE linker
+ * table's solution (iPXE commit 67a10ef000cb7 [0]).  To see how this code
+ * evolved or to extend and test and use this code in userspace refer to the
+ * userspace linker-table tree [1].  This repository can be used for ease of
+ * testing of extensions and sampling of changes prior to inclusion into Linux,
+ * it is intended to be kept up to date to match Linux's solution. Contrary to
+ * iPXE's solution, which strives to force compilation of everything using
+ * linker tables, Linux's solution allows for developers to be selective over
+ * where one wishes to force compilation, this then is just an optional feature
+ * for the Linux linker table solution.
+ *
+ * [0] git://git.ipxe.org/ipxe.git
+ *
+ * [1] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linker-tables.git/
+ */
+
+/**
+ * DOC: The code bit-rot problem
+ *
+ * Overuse of C #ifdefs can be problematic for certain types of code.  Linux
+ * provides a rich array of features, but all these features take up valuable
+ * space in a kernel image. The traditional solution to this problem has been
+ * for each feature to have its own Kconfig entry and for the respective code
+ * to be wrapped around #ifdefs, allowing the feature to be compiled in only
+ * if desired.
+ *
+ * The problem with this is that over time it becomes very difficult and time
+ * consuming to compile, let alone test, all possible versions of Linux. Code
+ * that is not typically used tends to suffer from bit-rot over time. It can
+ * become difficult to predict which combinations of compile-time options will
+ * result in code that can compile and link correctly.
+ */
+
+/**
+ * DOC: Avoiding the code bit-rot problem when desirable
+ *
+ * To solve the code bit-rot problem linker tables can be used on Linux, it
+ * enables you to always force compiling of select features that one wishes to
+ * avoid bit-rot while still enabling you to disable linking feature code into
+ * the final kernel image if the features have been disabled via Kconfig.
+ * Linux's linker tables allows for developers to be selective over where one
+ * wishes to take advantage of the optional feature of forcing compilation and
+ * only linking in enabled features.
+ *
+ * To use linker tables and to optionally take advantage of avoiding code
+ * bit-rot, feature code should be implemented in separate C files, and should
+ * be designed to always be compiled -- they should not be guarded with a C
+ * code #ifdef CONFIG_FOO statements, consideration must also be taken for
+ * sub-features which depend on the main CONFIG_FOO option, as they will be
+ * disabled if they depend on CONFIG_FOO and therefore not compiled. To force
+ * compilation and only link when features are needed a new optional target
+ * table-y can be used on Makefiles, documented below.
+ *
+ * Currently only built-in features are supported, modular support is not
+ * yet supported, however you can make use of sub-features for modules
+ * if they are independent and can simply be linked into modules.
+ */
+
+/**
+ * DOC: Using target table-y and table-n
+ *
+ * Let's assume we want to always force compilation of feature FOO in the
+ * kernel but avoid linking it. When you enable the FOO feature via Kconfig
+ * you'd end up with:
+ *
+ *	#define CONFIG_FOO 1
+ *
+ * You typically would then just use this on your Makefile to selectively
+ * compile and link the feature:
+ *
+ *	obj-$(CONFIG_FOO) += foo.o
+ *
+ * You could instead optionally use the new linker table object:
+ *
+ *	table-$(CONFIG_FOO) += foo.o
+ *
+ * Alternatively, this would be the equivalent of listing:
+ *
+ *	extra += foo.o
+ *	obj-$(CONFIG_FOO) += foo.o
+ *
+ * Both are mechanisms which can be used to take advantage of forcing
+ * compilation with linker tables, however making use of table-$(CONFIG_FOO)
+ * is encouraged as it helps with annotating linker tables clearly where
+ * compilation is forced.
+ */
+
+/**
+ * DOC: Opting out of forcing compilation
+ *
+ * If you want to opt-out of forcing compilation you would use the typical
+ * obj-$(CONFIG_FOO) += foo.o and foo.o will only be compiled and linked
+ * in when enabled. Using both table-$(CONFIG_FOO) and obj-($CONFIG_FOO)
+ * will result with the feature on your binary only if you've enabled
+ * CONFIG_FOO, however using table-$(CONFIG_FOO) will always force compilation,
+ * this is why avoiding code bit-rot is an optional fature for Linux linker
+ * tables.
+ */
+
+/**
+ * DOC: How linker tables simplify inits
+ *
+ * Traditionally, we would implement features in C code as follows:
+ *
+ *	foo_init();
+ *
+ * You'd then have a foo.h which would have:
+ *
+ *	#ifdef CONFIG_FOO
+ *	#else
+ *	static inline void foo(void) { }
+ *	#endif
+ *
+ * With linker tables this is no longer necessary as your init routines would
+ * be implicit, you'd instead call:
+ *
+ *	call_init_fns();
+ *
+ * call_init_fns() would call all functions present in your init table and if
+ * and only if foo.o gets linked in, then its initialisation function will be
+ * called, whether you use obj-$(CONFIG_FOO) or table-$(CONFIG_FOO).
+ *
+ * The linker script takes care of assembling the tables for us. All of our
+ * table sections have names of the format SECTION_NAME*.tbl.NAME.N. Here
+ * SECTION_NAME is one of the standard sections in include/linux/sections.h,
+ * and NAME designates the specific use case for the linker table, the table.
+ * N is a digit decimal number used to impose an "order level" upon the tables
+ * if required. NN= (empty string) is reserved for the symbol indicating "table
+ * start", and N=~ is reserved for the symbol indicating "table end". In order
+ * for the call_init_fns() to work behind the scenes the custom linker script
+ * would need to define the beginning of the table, the end of the table, and
+ * in between it should use SORT() to give order-level effect. Now, typically
+ * such type of requirements would require custom linker script modifications
+ * but Linux's linker tables builds on top of already existing standard Linux
+ * ELF sections, each with different purposes. This lets you build and add
+ * new tables without needing custom linker script modifications. This is
+ * also done to support all architectures. All that is needed then is to
+ * ensure a respective common linker table entry is added to the shared
+ * include/asm-generic/vmlinux.lds.h. There should be a respective:
+ *
+ *	*(SORT(SECTION_TBL_ALL(SECTION_NAME)))
+ *
+ * entry for each type of supported section there. If your SECTION_NAME
+ * is not yet supported, consider adding support for it.
+ *
+ * The order-level is really only a helper, if only one order level is
+ * used, the next contributing factor to order is the order of the code
+ * in the C file, and the order of the objects in the Makefile. Using
+ * an order level then should not really be needed in most cases, its
+ * use however enables to compartamentalize code into tables where ordering
+ * through C file or through the Makefile would otherwise be very difficult
+ * or if one wanted to enable very specific initialization semantics.
+ *
+ * As an example, suppose that we want to create a "frobnicator"
+ * feature framework, and allow for several independent modules to
+ * provide frobnicating services. Then we would create a frob.h
+ * header file containing e.g.
+ *
+ *	struct frobnicator {
+ *		const char *name;
+ *		void (*frob) (void);
+ *	};
+ *
+ *	DECLARE_LINKTABLE(struct frobnicator, frobnicator_fns);
+ *
+ * Any module providing frobnicating services would look something
+ * like
+ *
+ *	#include "frob.h"
+ *	static void my_frob(void) {
+ *		... Do my frobnicating
+ *	}
+ *	LINKTABLE_INIT_DATA(frobnicator_fns, all) my_frobnicator = {
+ *		.name = "my_frob",
+ *		.frob = my_frob,
+ *	};
+ *
+ * The central frobnicator code (frob.c) would use the frobnicating
+ * modules as follows
+ *
+ *	#include "frob.h"
+ *
+ *	void frob_all(void) {
+ *		struct frob *frob;
+ *
+ *		LINKTABLE_FOR_EACH(frob, frobnicator_fns) {
+ *			pr_info("Calling frobnicator \"%s\"\n", frob->name);
+ *			frob->frob();
+ *		}
+ *	}
+ */
+
+/**
+ * DOC: Linker table helpers
+ *
+ * These are helpers for linker tables.
+ */
+
+/**
+ * LINKTABLE_ADDR_WITHIN - returns true if address is in range
+ *
+ * @tbl: linker table
+ * @addr: address to query for
+ *
+ * Returns true if the address is part of the linker table.
+ */
+#define LINKTABLE_ADDR_WITHIN(tbl, addr)				\
+	 (addr >= (unsigned long) LINUX_SECTION_START(tbl) &&		\
+          addr < (unsigned long) LINUX_SECTION_END(tbl))
+
+/**
+ * DOC: Constructing linker tables
+ *
+ * Linker tables constructors are used to build an entry into a linker table.
+ * Linker table constructors exist for each type of supported section.
+ *
+ * You have weak and regular type of link table entry constructors.
+ */
+
+/**
+ * DOC: Weak linker tables constructors
+ *
+ * The weak attribute is desirable if you want an entry you can replace at
+ * link time. A very special use case for linker tables is the first entry.
+ * A weak attribute is used for the first entry to ensure that this entry's
+ * address matches the end address of the table when the linker table is
+ * emtpy, but will also point to the first real entry of the table once not
+ * empty. When the first entry is linked in, it takes place of the first entry.
+ */
+
+/**
+ * LINKTABLE_WEAK - Constructs a weak linker table entry for data
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Constructs a weak linker table for data.
+ */
+#define LINKTABLE_WEAK(name, level)					\
+	      __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     weak,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_DATA, name, level))))
+
+/**
+ * LINKTABLE_TEXT_WEAK - Constructs a weak linker table entry for execution
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Constructs a weak linker table for code execution. These will be
+ * read-only.
+ */
+#define LINKTABLE_TEXT_WEAK(name, level)				\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     weak,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_TEXT, name, level))))
+
+/**
+ * LINKTABLE_RO_WEAK - Constructs a weak read-only linker table entry
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Constructs a weak linker table which only requires read-only access.
+ */
+#define LINKTABLE_RO_WEAK(name, level)					\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     weak,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_RODATA, name, level))))
+
+/**
+ * LINKTABLE_INIT_WEAK - Constructs a weak linker table entry for init code
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Constructs a weak linker table for execution. use at init.
+ */
+#define LINKTABLE_INIT_WEAK(name, level)				\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     weak,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_INIT, name, level))))
+
+/**
+ * LINKTABLE_INIT_DATA_WEAK - Constructs a weak linker table entry for initdata
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Constructs a weak linker table for data during init.
+ */
+#define LINKTABLE_INIT_DATA_WEAK(name, level)				\
+	      __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     weak,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_INIT_DATA, name, level))))
+
+/**
+ * DOC: Regular linker linker table constructors
+ *
+ * Regular constructors are expected to be used for valid linker table entries.
+ * Valid uses of weak entries other than the beginning and is currently
+ * untested but should in theory work.
+ */
+
+/**
+ * LINKTABLE - Declares a data linker table entry
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Declares a data linker table entry. These are read-write.
+ */
+#define LINKTABLE(name, level)						\
+	      __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_DATA, name, level))))
+
+/**
+ * LINKTABLE_TEXT - Declares a linker table entry for execution
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Declares a linker table to be used for execution.
+ */
+#define LINKTABLE_TEXT(name, level)					\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_TEXT, name, level))))
+
+/**
+ * LINKTABLE_RO - Declares a read-only linker table entry.
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Declares a linker table which only requires read-only access.
+ */
+#define LINKTABLE_RO(name, level)					\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_RODATA, name, level))))
+
+/**
+ * LINKTABLE_INIT - Declares a linker table entry to be used on init.
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Declares a linker table entry for execution use during init.
+ */
+#define LINKTABLE_INIT(name, level)					\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     __aligned__(LINUX_SECTION_ALIGN_FUNC),	\
+			     section(SECTION_TBL(SECTION_INIT, name, level))))
+
+/**
+ * LINKTABLE_INIT_DATA - Declares a linker table entry to be used on init data.
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Declares a linker table entry for data during init.
+ */
+#define LINKTABLE_INIT_DATA(name, level)					\
+	      __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_INIT_DATA, name, level))))
+
+/**
+ * DOC: Declaring Linker tables
+ *
+ * Declarers are used to help code access the linker tables. Typically
+ * header files for subsystems would declare the linker tables to enable
+ * easy access to add new entries, and to iterate over the list of table.
+ */
+
+
+/**
+ * DECLARE_LINKTABLE - Declares a data linker table entry
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Declares a data linker table entry.
+ */
+#define DECLARE_LINKTABLE(type, name)					\
+	DECLARE_LINUX_SECTION(type, name)
+
+/**
+ * DECLARE_LINKTABLE_RO - Declares a read-only linker table entry
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Declares a read-only linker table entry.
+ */
+#define DECLARE_LINKTABLE_RO(type, name)				\
+	DECLARE_LINUX_SECTION_RO(type, name)
+
+/**
+ * DOC: Defining Linker tables
+ *
+ * Linker tables are defined in the code that takes ownership over
+ * the linker table. This is typically done in the same code that is in
+ * charge of iterating over the linker table as well.
+ */
+
+/**
+ * DEFINE_LINKTABLE - Defines a linker table for data
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Defines a linker table which used for data.
+ */
+#define DEFINE_LINKTABLE(type, name)					\
+	DECLARE_LINKTABLE(type, name);					\
+	LINKTABLE_WEAK(name, ) VMLINUX_SYMBOL(name)[0] = {};		\
+	LINKTABLE(name, ~) VMLINUX_SYMBOL(name##__end)[0] = {};
+
+/**
+ * DEFINE_LINKTABLE_TEXT - Declares linker table entry for exectuion
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Declares a linker table entry for execution.
+ */
+#define DEFINE_LINKTABLE_TEXT(type, name)				\
+	DECLARE_LINKTABLE_RO(type, name);				\
+	LINKTABLE_TEXT_WEAK(name, ) VMLINUX_SYMBOL(name)[0] = {};	\
+	LINKTABLE_TEXT(name, ~) VMLINUX_SYMBOL(name##__end)[0] = {};
+
+/**
+ * DEFINE_LINKTABLE_RO - Defines a read-only linker table
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Defines a linker table which we know only requires read-only access.
+ */
+#define DEFINE_LINKTABLE_RO(type, name)					\
+	DECLARE_LINKTABLE_RO(type, name);				\
+	LINKTABLE_RO_WEAK(name, ) VMLINUX_SYMBOL(name)[0] = {};		\
+	LINKTABLE_RO(name, ~) VMLINUX_SYMBOL(name##__end)[0] = {};
+
+/**
+ * DEFINE_LINKTABLE_INIT - Defines an init time linker table for execution
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Defines a linker table. If you are adding a new type you should
+ * enable CONFIG_DEBUG_SECTION_MISMATCH and ensure routines that make
+ * use of the linker tables get a respective __ref tag.
+ */
+#define DEFINE_LINKTABLE_INIT(type, name)				\
+	DECLARE_LINKTABLE(type, name);					\
+	LINKTABLE_INIT_WEAK(name, ) VMLINUX_SYMBOL(name)[0] = {};	\
+	LINKTABLE_INIT(name, ~) VMLINUX_SYMBOL(name##__end)[0] = {};
+
+/**
+ * DEFINE_LINKTABLE_INIT_DATA - Defines an init time linker table for data
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Defines a linker table for init data. If you are adding a new type you
+ * should enable CONFIG_DEBUG_SECTION_MISMATCH and ensure routines that make
+ * use of the linker tables get a respective __ref tag.
+ */
+#define DEFINE_LINKTABLE_INIT_DATA(type, name)				\
+	DECLARE_LINKTABLE(type, name);					\
+	LINKTABLE_INIT_DATA_WEAK(name, ) VMLINUX_SYMBOL(name)[0] = {};	\
+	LINKTABLE_INIT_DATA(name, ~) VMLINUX_SYMBOL(name##__end)[0] = {};
+
+/**
+ * DOC: Iterating over Linker tables
+ *
+ * To make use of the linker tables you want to be able to iterate over
+ * them. This section documents the different iterators available.
+ */
+
+/**
+ * LINKTABLE_FOR_EACH - iterate through all entries within a linker table
+ *
+ * @pointer: entry pointer
+ * @tbl: linker table
+ *
+ * Example usage:
+ *
+ *   struct frobnicator *frob;
+ *
+ *   LINKTABLE_FOR_EACH(frob, frobnicator_fns) {
+ *     ...
+ *   }
+ */
+
+#define LINKTABLE_FOR_EACH(pointer, tbl)				\
+	for (pointer = LINUX_SECTION_START(tbl);			\
+	     pointer < LINUX_SECTION_END(tbl);				\
+	     pointer++)
+
+/**
+ * LINKTABLE_RUN_ALL - iterate and run through all entries on a linker table
+ *
+ * @tbl: linker table
+ * @func: structure name for the function name we want to call.
+ * @args...: arguments to pass to func
+ *
+ * Example usage:
+ *
+ *   LINKTABLE_RUN_ALL(frobnicator_fns, some_run,);
+ */
+#define LINKTABLE_RUN_ALL(tbl, func, args...)				\
+do {									\
+	size_t i;							\
+	for (i = 0; i < LINUX_SECTION_SIZE(tbl); i++)			\
+		(tbl[i]).func (args);					\
+} while (0);
+
+/**
+ * LINKTABLE_RUN_ERR - run each linker table entry func and return error if any
+ *
+ * @tbl: linker table
+ * @func: structure name for the function name we want to call.
+ * @args...: arguments to pass to func
+ *
+ * Example usage:
+ *
+ *   unsigned int err = LINKTABLE_RUN_ERR(frobnicator_fns, some_run,);
+ */
+#define LINKTABLE_RUN_ERR(tbl, func, args...)				\
+({									\
+	size_t i;							\
+	int err = 0;							\
+	for (i = 0; !err && i < LINUX_SECTION_SIZE(tbl); i++)		\
+		err = (tbl[i]).func (args);				\
+		err; \
+})
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _LINUX_LINKER_TABLES_H */
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 11602e5efb3b..002857fe8d0d 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -91,7 +91,7 @@ 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) $(table-y)) \
 	 $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \
 	 $(subdir-ym) $(always)
 	@:
@@ -326,7 +326,7 @@ $(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 += $(extra-y) $(table-y) $(MAKECMDGOALS) $(always)
 
 # Linker scripts preprocessor (.lds.S -> .lds)
 # ---------------------------------------------------------------------------
diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
index 50616ea25131..bdc29810dae5 100644
--- a/scripts/Makefile.clean
+++ b/scripts/Makefile.clean
@@ -36,6 +36,7 @@ subdir-ymn	:= $(addprefix $(obj)/,$(subdir-ymn))
 # directory
 
 __clean-files	:= $(extra-y) $(extra-m) $(extra-)       \
+		   $(table-y) $(table-m) $(table-)       \
 		   $(always) $(targets) $(clean-files)   \
 		   $(host-progs)                         \
 		   $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 0a07f9014944..494f215ebaa4 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -12,6 +12,16 @@ export KBUILD_SUBDIR_CCFLAGS := $(KBUILD_SUBDIR_CCFLAGS) $(subdir-ccflags-y)
 # Figure out what we need to build from the various variables
 # ===========================================================================
 
+# Linker tables objects always wish to be built to avoid bit-rot in
+# code, but only linked in *iff* they were enabled. We accomplish this
+# using pegging linker table objects into extra-y, which forces
+# compilation and then using the respective table-y and table-m as
+# as hints for things we do want enabled. Objects which we want to
+# avoid linking in will be in table-, not table-y and table-m.
+extra-y += $(table-)
+obj-m += $(table-m)
+obj-y += $(table-y)
+
 # When an object is listed to be built compiled-in and modular,
 # only build the compiled-in version
 
@@ -72,6 +82,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))
+table-y		:= $(addprefix $(obj)/,$(table-y))
+table-m		:= $(addprefix $(obj)/,$(table-m))
 always		:= $(addprefix $(obj)/,$(always))
 targets		:= $(addprefix $(obj)/,$(targets))
 modorder	:= $(addprefix $(obj)/,$(modorder))
diff --git a/tools/include/linux/sections.h b/tools/include/linux/sections.h
new file mode 100644
index 000000000000..cc6f07f11583
--- /dev/null
+++ b/tools/include/linux/sections.h
@@ -0,0 +1,13 @@
+#ifndef _TOOLS_LINUX_SECTIONS_H_
+
+/* Mostly a copy of what we need only */
+
+#define SECTION_INIT			.init.text
+#define SECTION_RODATA			.rodata
+
+#define ___SECTION_TBL_STR(section, name)				\
+	#section ".tbl." #name
+#define SECTION_TBL_ALL_STR(section)					\
+	___SECTION_TBL_STR(section, *)
+
+#endif /* _TOOLS_LINUX_SECTIONS_H_ */
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 07/13] tables.h: add linker table support
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe, Luis R. Rodriguez

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
originally based on Michael Brown's iPXE's linker table solution but
has been significantly modified to fit Linux's use in its integration.

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.

Bit rotting avoidance is enabled by *granting the option* to force
compilation of code and only enable linking object code in when
specific features have been enabled. It accomplishes this by using
linker sections, the lightweight feature ordering of code is enabled
by taking advantage of the old binutils ld SORT() on features
specific sections.

Contrary to iPXE's solution, which strives to force compilation
of all features, Linux' solution strives to encourage usage of linker
tables to force compilation of code *only on designated code*. Linker
tables can be used without requiring one to force code compilation
of features that use it though, to take advantage of the simplification
of init sequences.

Linux code that uses linker tables *and* wishes to always require
compilation but selectively linking must use new kbuild target object
that helps accomplishes this, table-y. Linux code that uses linker
tables but does not want to require forcing compilation can use the
good 'ol obj-y targets.

Used commit 67a10ef000cb7 from iPXE upstream [0] as the starting point
for development and evaluation of Linux's integration, further changes
made and evaluation of different linker table options for Linux are
available on the linker-table userspace tree [1].

[0] git://git.ipxe.org/ipxe.git
[1] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linker-tables.git/

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.

Cc: Michael Brown <mcb30@ipxe.org>
Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 Documentation/DocBook/Makefile           |   2 +-
 Documentation/DocBook/linker-tables.tmpl | 166 +++++++++
 Documentation/kbuild/makefiles.txt       |  19 +
 arch/alpha/include/asm/tables.h          |   6 +
 arch/arc/include/asm/tables.h            |   6 +
 arch/arm/include/asm/tables.h            |   6 +
 arch/arm64/include/asm/tables.h          |   6 +
 arch/avr32/include/asm/tables.h          |   6 +
 arch/blackfin/include/asm/tables.h       |   6 +
 arch/c6x/include/asm/tables.h            |   6 +
 arch/cris/include/asm/tables.h           |   6 +
 arch/frv/include/asm/tables.h            |   6 +
 arch/h8300/include/asm/tables.h          |   6 +
 arch/hexagon/include/asm/tables.h        |   6 +
 arch/ia64/include/asm/tables.h           |   6 +
 arch/m32r/include/asm/tables.h           |   6 +
 arch/m68k/include/asm/tables.h           |   6 +
 arch/metag/include/asm/tables.h          |   6 +
 arch/microblaze/include/asm/tables.h     |   6 +
 arch/mips/include/asm/tables.h           |   6 +
 arch/mn10300/include/asm/tables.h        |   6 +
 arch/nios2/include/asm/tables.h          |   6 +
 arch/openrisc/include/asm/tables.h       |   6 +
 arch/parisc/include/asm/tables.h         |   6 +
 arch/powerpc/include/asm/tables.h        |   6 +
 arch/s390/include/asm/tables.h           |   6 +
 arch/score/include/asm/tables.h          |   6 +
 arch/sh/include/asm/tables.h             |   6 +
 arch/sparc/include/asm/tables.h          |   6 +
 arch/tile/include/asm/tables.h           |   6 +
 arch/um/include/asm/tables.h             |   6 +
 arch/unicore32/include/asm/tables.h      |   6 +
 arch/x86/include/asm/tables.h            |   6 +
 arch/x86/tools/relocs.c                  |   3 +
 arch/xtensa/include/asm/tables.h         |   6 +
 include/asm-generic/tables.h             |  70 ++++
 include/asm-generic/vmlinux.lds.h        |   9 +-
 include/linux/tables.h                   | 597 +++++++++++++++++++++++++++++++
 scripts/Makefile.build                   |   4 +-
 scripts/Makefile.clean                   |   1 +
 scripts/Makefile.lib                     |  12 +
 tools/include/linux/sections.h           |  13 +
 42 files changed, 1078 insertions(+), 4 deletions(-)
 create mode 100644 Documentation/DocBook/linker-tables.tmpl
 create mode 100644 arch/alpha/include/asm/tables.h
 create mode 100644 arch/arc/include/asm/tables.h
 create mode 100644 arch/arm/include/asm/tables.h
 create mode 100644 arch/arm64/include/asm/tables.h
 create mode 100644 arch/avr32/include/asm/tables.h
 create mode 100644 arch/blackfin/include/asm/tables.h
 create mode 100644 arch/c6x/include/asm/tables.h
 create mode 100644 arch/cris/include/asm/tables.h
 create mode 100644 arch/frv/include/asm/tables.h
 create mode 100644 arch/h8300/include/asm/tables.h
 create mode 100644 arch/hexagon/include/asm/tables.h
 create mode 100644 arch/ia64/include/asm/tables.h
 create mode 100644 arch/m32r/include/asm/tables.h
 create mode 100644 arch/m68k/include/asm/tables.h
 create mode 100644 arch/metag/include/asm/tables.h
 create mode 100644 arch/microblaze/include/asm/tables.h
 create mode 100644 arch/mips/include/asm/tables.h
 create mode 100644 arch/mn10300/include/asm/tables.h
 create mode 100644 arch/nios2/include/asm/tables.h
 create mode 100644 arch/openrisc/include/asm/tables.h
 create mode 100644 arch/parisc/include/asm/tables.h
 create mode 100644 arch/powerpc/include/asm/tables.h
 create mode 100644 arch/s390/include/asm/tables.h
 create mode 100644 arch/score/include/asm/tables.h
 create mode 100644 arch/sh/include/asm/tables.h
 create mode 100644 arch/sparc/include/asm/tables.h
 create mode 100644 arch/tile/include/asm/tables.h
 create mode 100644 arch/um/include/asm/tables.h
 create mode 100644 arch/unicore32/include/asm/tables.h
 create mode 100644 arch/x86/include/asm/tables.h
 create mode 100644 arch/xtensa/include/asm/tables.h
 create mode 100644 include/asm-generic/tables.h
 create mode 100644 include/linux/tables.h
 create mode 100644 tools/include/linux/sections.h

diff --git a/Documentation/DocBook/Makefile b/Documentation/DocBook/Makefile
index 1b2ac4731418..b78365cc3cd1 100644
--- a/Documentation/DocBook/Makefile
+++ b/Documentation/DocBook/Makefile
@@ -18,7 +18,7 @@ DOCBOOKS := z8530book.xml device-drivers.xml \
 	    alsa-driver-api.xml writing-an-alsa-driver.xml \
 	    tracepoint.xml media_api.xml w1.xml \
 	    writing_musb_glue_layer.xml crypto-API.xml iio.xml \
-	    sections.xml
+	    sections.xml linker-tables.xml
 
 include Documentation/DocBook/media/Makefile
 
diff --git a/Documentation/DocBook/linker-tables.tmpl b/Documentation/DocBook/linker-tables.tmpl
new file mode 100644
index 000000000000..fba90c61eee1
--- /dev/null
+++ b/Documentation/DocBook/linker-tables.tmpl
@@ -0,0 +1,166 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE set PUBLIC "-//OASIS//DTD DocBook XML V4.1.2//EN"
+	"http://www.oasis-open.org/docbook/xml/4.1.2/docbookx.dtd" []>
+<set>
+  <setinfo>
+    <title>Linux linker tables</title>
+    <subtitle>
+      Explains Linux' linker tables work.
+    </subtitle>
+
+    <copyright>
+      <year>2015-2016</year>
+      <holder>Luis R. Rodriguez</holder>
+    </copyright>
+
+    <authorgroup>
+      <author>
+        <firstname>Luis</firstname>
+        <surname>Rodriguez</surname>
+        <affiliation>
+          <address><email>mcgrof@kernel.org</email></address>
+        </affiliation>
+      </author>
+    </authorgroup>
+
+    <legalnotice>
+      <para>
+        This documentation is free software; you can redistribute
+        it and/or modify it under the terms of the GNU General Public
+        License version 2 as published by the Free Software Foundation.
+      </para>
+      <para>
+        This documentation is distributed in the hope that it will be
+        useful, but WITHOUT ANY WARRANTY; without even the implied
+        warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
+        See the GNU General Public License for more details.
+      </para>
+      <para>
+        You should have received a copy of the GNU General Public
+        License along with this documentation; if not, write to the Free
+        Software Foundation, Inc., 59 Temple Place, Suite 330, Boston,
+        MA 02111-1307 USA
+      </para>
+      <para>
+        For more details see the file COPYING in the source
+        distribution of Linux.
+      </para>
+    </legalnotice>
+
+    <abstract>
+      <para>
+        This book documents the Linux' use of linker tables, how you can
+        use them and how they work.
+      </para>
+    </abstract>
+  </setinfo>
+  <book id="linux-linux-tables">
+    <bookinfo>
+      <title>Linux linker tables</title>
+
+      <abstract>
+!Pinclude/linux/tables.h Introduction
+      </abstract>
+    </bookinfo>
+
+      <chapter>
+      <title>About Linker tables</title>
+
+	<sect1>
+	<title>Linker table provenance and userspace testing</title>
+!Pinclude/linux/tables.h Linker table provenance and userspace testing
+	</sect1>
+
+	<sect1>
+	<title>The code bit-rot problem</title>
+!Pinclude/linux/tables.h The code bit-rot problem
+	</sect1>
+
+	<sect1>
+	<title>Avoiding the code bit-rot problem when desirable</title>
+!Pinclude/linux/tables.h Avoiding the code bit-rot problem when desirable
+	</sect1>
+      </chapter>
+
+      <chapter>
+      <title>Using linker tables in Linux</title>
+
+	<sect1>
+      <title>Using target table-y and table-n</title>
+!Pinclude/linux/tables.h Using target table-y and table-n
+	</sect1>
+
+	<sect1>
+	<title>Opting out of forcing compilation</title>
+!Pinclude/linux/tables.h Opting out of forcing compilation
+	</sect1>
+
+	<sect1>
+	<title>How linker tables simplify inits</title>
+!Pinclude/linux/tables.h How linker tables simplify inits
+	</sect1>
+
+      </chapter>
+
+      <chapter>
+      <title>Linker table helpers</title>
+!Pinclude/linux/tables.h Linker table helpers
+!Finclude/linux/tables.h LINKTABLE_ADDR_WITHIN
+      </chapter>
+
+      <chapter>
+      <title>Constructing Linker tables</title>
+!Pinclude/linux/tables.h Constructing linker tables
+
+	<sect1>
+	<title>Weak linker tables constructors</title>
+!Pinclude/linux/tables.h Weak linker tables constructors
+!Finclude/linux/tables.h LINKTABLE_WEAK
+!Finclude/linux/tables.h LINKTABLE_TEXT_WEAK
+!Finclude/linux/tables.h LINKTABLE_DATA_WEAK
+!Finclude/linux/tables.h LINKTABLE_RO_WEAK
+!Finclude/linux/tables.h LINKTABLE_INIT_WEAK
+!Finclude/linux/tables.h LINKTABLE_INIT_DATA_WEAK
+	</sect1>
+
+	<sect1>
+	<title>Regular linker linker table constructors</title>
+!Pinclude/linux/tables.h Regular linker linker table constructors
+!Finclude/linux/tables.h LINKTABLE_TEXT
+!Finclude/linux/tables.h LINKTABLE_DATA
+!Finclude/linux/tables.h LINKTABLE_RO
+!Finclude/linux/tables.h LINKTABLE_INIT
+!Finclude/linux/tables.h LINKTABLE_INIT_DATA
+	</sect1>
+      </chapter>
+
+      <chapter>
+      <title>Declaring Linker tables</title>
+!Pinclude/linux/tables.h Declaring Linker tables
+!Finclude/linux/tables.h DECLARE_LINKTABLE_TEXT
+!Finclude/linux/tables.h DECLARE_LINKTABLE_DATA
+!Finclude/linux/tables.h DECLARE_LINKTABLE_RO
+!Finclude/linux/tables.h DECLARE_LINKTABLE_INIT
+!Finclude/linux/tables.h DECLARE_LINKTABLE_INIT_DATA
+      </chapter>
+
+      <chapter>
+      <title>Defining Linker tables</title>
+!Pinclude/linux/tables.h Defining Linker tables
+!Finclude/linux/tables.h DEFINE_LINKTABLE_TEXT
+!Finclude/linux/tables.h DEFINE_LINKTABLE_DATA
+!Finclude/linux/tables.h DEFINE_LINKTABLE_RO
+!Finclude/linux/tables.h DEFINE_LINKTABLE_INIT
+!Finclude/linux/tables.h DEFINE_LINKTABLE_INIT_DATA
+      </chapter>
+
+      <chapter>
+      <title>Iterating over Linker tables</title>
+!Pinclude/linux/tables.h Iterating over Linker tables
+!Finclude/linux/tables.h LINKTABLE_FOR_EACH
+!Finclude/linux/tables.h LINKTABLE_RUN_ALL
+!Finclude/linux/tables.h LINKTABLE_RUN_ERR
+      </chapter>
+
+  </book>
+</set>
diff --git a/Documentation/kbuild/makefiles.txt b/Documentation/kbuild/makefiles.txt
index 385a5ef41c17..c63751312810 100644
--- a/Documentation/kbuild/makefiles.txt
+++ b/Documentation/kbuild/makefiles.txt
@@ -1089,6 +1089,25 @@ 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.
 
+    table-y table-m and table-
+
+	To avoid code bit-rot you may wish to avoid using #ifdefs on your
+	code. Bit-rot is possible if certain features may not be enabled
+	on certain build environments. The table-y, specifies targets which you
+	always wish to force compilation on, but wish to only enable linking in
+	if the feature is enabled, these are features taking advantage of
+	Linux's linker tables. For details on how to implement a feature using
+	linker tablesrefer to include/linux/tables.h. Use of table-m is not
+	yet supported.
+
+	Example:
+		table-$(CONFIG-FEATURE_FOO) += foo.o
+
+	An alternative to using table-y, is to use extra-y followed by the
+	respective obj-y:
+
+		extra-y += foo.o
+		obj-$(CONFIG-FEATURE_FOO) += foo.o
 
 --- 6.7 Commands useful for building a boot image
 
diff --git a/arch/alpha/include/asm/tables.h b/arch/alpha/include/asm/tables.h
new file mode 100644
index 000000000000..e53ee883330c
--- /dev/null
+++ b/arch/alpha/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ALPHA_TABLES_H
+#define _ASM_ALPHA_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_ALPHA_TABLES_H */
diff --git a/arch/arc/include/asm/tables.h b/arch/arc/include/asm/tables.h
new file mode 100644
index 000000000000..a02e790bcb14
--- /dev/null
+++ b/arch/arc/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARC_TABLES_H
+#define _ASM_ARC_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_ARC_TABLES_H */
diff --git a/arch/arm/include/asm/tables.h b/arch/arm/include/asm/tables.h
new file mode 100644
index 000000000000..96c1147fb766
--- /dev/null
+++ b/arch/arm/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARM_TABLES_H
+#define _ASM_ARM_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_ARM_TABLES_H */
diff --git a/arch/arm64/include/asm/tables.h b/arch/arm64/include/asm/tables.h
new file mode 100644
index 000000000000..d84a554ec6da
--- /dev/null
+++ b/arch/arm64/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_ARM64_TABLES_H
+#define _ASM_ARM64_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_ARM64_TABLES_H */
diff --git a/arch/avr32/include/asm/tables.h b/arch/avr32/include/asm/tables.h
new file mode 100644
index 000000000000..7ef914761c38
--- /dev/null
+++ b/arch/avr32/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_AVR32_TABLES_H
+#define _ASM_AVR32_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_AVR32_TABLES_H */
diff --git a/arch/blackfin/include/asm/tables.h b/arch/blackfin/include/asm/tables.h
new file mode 100644
index 000000000000..6e7445818a9c
--- /dev/null
+++ b/arch/blackfin/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_BLACKFIN_TABLES_H
+#define _ASM_BLACKFIN_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_BLACKFIN_TABLES_H */
diff --git a/arch/c6x/include/asm/tables.h b/arch/c6x/include/asm/tables.h
new file mode 100644
index 000000000000..209642925772
--- /dev/null
+++ b/arch/c6x/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_C6X_TABLES_H
+#define _ASM_C6X_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_C6X_TABLES_H */
diff --git a/arch/cris/include/asm/tables.h b/arch/cris/include/asm/tables.h
new file mode 100644
index 000000000000..17c0f04e7c27
--- /dev/null
+++ b/arch/cris/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_CRIS_TABLES_H
+#define _ASM_CRIS_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_CRIS_TABLES_H */
diff --git a/arch/frv/include/asm/tables.h b/arch/frv/include/asm/tables.h
new file mode 100644
index 000000000000..7a6c1f263a07
--- /dev/null
+++ b/arch/frv/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_FRV_TABLES_H
+#define _ASM_FRV_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_FRV_TABLES_H */
diff --git a/arch/h8300/include/asm/tables.h b/arch/h8300/include/asm/tables.h
new file mode 100644
index 000000000000..fc4297961bb7
--- /dev/null
+++ b/arch/h8300/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_H8300_TABLES_H
+#define _ASM_H8300_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_H8300_TABLES_H */
diff --git a/arch/hexagon/include/asm/tables.h b/arch/hexagon/include/asm/tables.h
new file mode 100644
index 000000000000..73475cc63c77
--- /dev/null
+++ b/arch/hexagon/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_HEXAGON_TABLES_H
+#define _ASM_HEXAGON_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_HEXAGON_TABLES_H */
diff --git a/arch/ia64/include/asm/tables.h b/arch/ia64/include/asm/tables.h
new file mode 100644
index 000000000000..4d7084cf0bd4
--- /dev/null
+++ b/arch/ia64/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_IA64_TABLES_H
+#define _ASM_IA64_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_IA64_TABLES_H */
diff --git a/arch/m32r/include/asm/tables.h b/arch/m32r/include/asm/tables.h
new file mode 100644
index 000000000000..6708322deba8
--- /dev/null
+++ b/arch/m32r/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_M32R_TABLES_H
+#define _ASM_M32R_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_M32R_TABLES_H */
diff --git a/arch/m68k/include/asm/tables.h b/arch/m68k/include/asm/tables.h
new file mode 100644
index 000000000000..1f6def4822ff
--- /dev/null
+++ b/arch/m68k/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_M68K_TABLES_H
+#define _ASM_M68K_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_M68K_TABLES_H */
diff --git a/arch/metag/include/asm/tables.h b/arch/metag/include/asm/tables.h
new file mode 100644
index 000000000000..594ee23ab968
--- /dev/null
+++ b/arch/metag/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_METAG_TABLES_H
+#define _ASM_METAG_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_METAG_TABLES_H */
diff --git a/arch/microblaze/include/asm/tables.h b/arch/microblaze/include/asm/tables.h
new file mode 100644
index 000000000000..f84bbfbdd63c
--- /dev/null
+++ b/arch/microblaze/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MICROBLAZE_TABLES_H
+#define _ASM_MICROBLAZE_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_MICROBLAZE_TABLES_H */
diff --git a/arch/mips/include/asm/tables.h b/arch/mips/include/asm/tables.h
new file mode 100644
index 000000000000..db5d62983667
--- /dev/null
+++ b/arch/mips/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MIPS_TABLES_H
+#define _ASM_MIPS_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_MIPS_TABLES_H */
diff --git a/arch/mn10300/include/asm/tables.h b/arch/mn10300/include/asm/tables.h
new file mode 100644
index 000000000000..b6d19fb66119
--- /dev/null
+++ b/arch/mn10300/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_MN10300_TABLES_H
+#define _ASM_MN10300_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_MN10300_TABLES_H */
diff --git a/arch/nios2/include/asm/tables.h b/arch/nios2/include/asm/tables.h
new file mode 100644
index 000000000000..5dce7fc56bf7
--- /dev/null
+++ b/arch/nios2/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_NIOS2_TABLES_H
+#define _ASM_NIOS2_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_NIOS2_TABLES_H */
diff --git a/arch/openrisc/include/asm/tables.h b/arch/openrisc/include/asm/tables.h
new file mode 100644
index 000000000000..1b052c3b1816
--- /dev/null
+++ b/arch/openrisc/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_OPENRISC_TABLES_H
+#define _ASM_OPENRISC_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_OPENRISC_TABLES_H */
diff --git a/arch/parisc/include/asm/tables.h b/arch/parisc/include/asm/tables.h
new file mode 100644
index 000000000000..da60f2d9588d
--- /dev/null
+++ b/arch/parisc/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_PARISC_TABLES_H
+#define _ASM_PARISC_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_PARISC_TABLES_H */
diff --git a/arch/powerpc/include/asm/tables.h b/arch/powerpc/include/asm/tables.h
new file mode 100644
index 000000000000..1615f2edc4fc
--- /dev/null
+++ b/arch/powerpc/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_POWERPC_TABLES_H
+#define _ASM_POWERPC_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_POWERPC_TABLES_H */
diff --git a/arch/s390/include/asm/tables.h b/arch/s390/include/asm/tables.h
new file mode 100644
index 000000000000..c9615ed026b2
--- /dev/null
+++ b/arch/s390/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_S390_TABLES_H
+#define _ASM_S390_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_S390_TABLES_H */
diff --git a/arch/score/include/asm/tables.h b/arch/score/include/asm/tables.h
new file mode 100644
index 000000000000..7694b5bfca91
--- /dev/null
+++ b/arch/score/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SCORE_TABLES_H
+#define _ASM_SCORE_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_SCORE_TABLES_H */
diff --git a/arch/sh/include/asm/tables.h b/arch/sh/include/asm/tables.h
new file mode 100644
index 000000000000..7db4ffee4d7e
--- /dev/null
+++ b/arch/sh/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SH_TABLES_H
+#define _ASM_SH_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_SH_TABLES_H */
diff --git a/arch/sparc/include/asm/tables.h b/arch/sparc/include/asm/tables.h
new file mode 100644
index 000000000000..c540236bd9f5
--- /dev/null
+++ b/arch/sparc/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_SPARC_TABLES_H
+#define _ASM_SPARC_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_SPARC_TABLES_H */
diff --git a/arch/tile/include/asm/tables.h b/arch/tile/include/asm/tables.h
new file mode 100644
index 000000000000..33168b49a295
--- /dev/null
+++ b/arch/tile/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_TILE_TABLES_H
+#define _ASM_TILE_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_TILE_TABLES_H */
diff --git a/arch/um/include/asm/tables.h b/arch/um/include/asm/tables.h
new file mode 100644
index 000000000000..ed093477c617
--- /dev/null
+++ b/arch/um/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_UM_TABLES_H
+#define _ASM_UM_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_UM_TABLES_H */
diff --git a/arch/unicore32/include/asm/tables.h b/arch/unicore32/include/asm/tables.h
new file mode 100644
index 000000000000..6edc65c625f5
--- /dev/null
+++ b/arch/unicore32/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_UNICORE32_TABLES_H
+#define _ASM_UNICORE32_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_UNICORE32_TABLES_H */
diff --git a/arch/x86/include/asm/tables.h b/arch/x86/include/asm/tables.h
new file mode 100644
index 000000000000..5828e3a73a61
--- /dev/null
+++ b/arch/x86/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_X86_TABLES_H
+#define _ASM_X86_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_X86_TABLES_H */
diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
index 0c2fae8d929d..07b335c67139 100644
--- a/arch/x86/tools/relocs.c
+++ b/arch/x86/tools/relocs.c
@@ -1,4 +1,5 @@
 /* This is included from relocs_32/64.c */
+#include <linux/sections.h>
 
 #define ElfW(type)		_ElfW(ELF_BITS, type)
 #define _ElfW(bits, type)	__ElfW(bits, type)
@@ -68,6 +69,8 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = {
 	"__end_rodata|"
 	"__initramfs_start|"
 	"(jiffies|jiffies_64)|"
+	SECTION_TBL_ALL_STR(SECTION_RODATA) "|"
+	SECTION_TBL_ALL_STR(SECTION_INIT) "|"
 #if ELF_BITS == 64
 	"__per_cpu_load|"
 	"init_per_cpu__.*|"
diff --git a/arch/xtensa/include/asm/tables.h b/arch/xtensa/include/asm/tables.h
new file mode 100644
index 000000000000..af78c7cd8e47
--- /dev/null
+++ b/arch/xtensa/include/asm/tables.h
@@ -0,0 +1,6 @@
+#ifndef _ASM_XTENSA_TABLES_H
+#define _ASM_XTENSA_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_XTENSA_TABLES_H */
diff --git a/include/asm-generic/tables.h b/include/asm-generic/tables.h
new file mode 100644
index 000000000000..5cf655590a19
--- /dev/null
+++ b/include/asm-generic/tables.h
@@ -0,0 +1,70 @@
+#ifndef _ASM_GENERIC_TABLES_H_
+#define _ASM_GENERIC_TABLES_H_
+/*
+ * Linux linker tables
+ *
+ * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
+ *
+ * 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/.
+ */
+
+#ifdef __KERNEL__
+# include <asm/sections.h>
+#endif /* __KERNEL__ */
+
+#define SECTION_TYPE_TABLES	tbl
+
+#define SECTION_TBL(section, name, level)				\
+	SECTION_TYPE(section, SECTION_TYPE_TABLES, name, level)
+
+#define SECTION_TBL_ALL(section)					\
+	SECTION_TYPE_ALL(section,SECTION_TYPE_TABLES)
+
+#ifndef section_tbl
+# define section_tbl(section, name, level, flags)			\
+	 section_type(section, SECTION_TYPE_TABLES, name,		\
+		     level, flags)
+#endif
+
+#ifndef section_tbl_any
+# define section_tbl_any(section, name, flags)				\
+	 section_type(section, SECTION_TYPE_TABLES, name,		\
+		     SECTION_ORDER_ANY, flags)
+#endif
+
+#ifndef section_tbl_asmtype
+# define section_tbl_asmtype(section, name, level, flags, asmtype)	\
+	 section_type_asmtype(section, SECTION_TYPE_TABLES, name,	\
+			     level, flags, asmtype)
+#endif
+
+#ifndef push_section_tbl
+# define push_section_tbl(section, name, level, flags)			\
+	 push_section_type(section, SECTION_TYPE_TABLES, name,		\
+			  level, flags)
+#endif
+
+#ifndef push_section_tbl_any
+# define push_section_tbl_any(section, name, flags)			\
+	 push_section_type(section, SECTION_TYPE_TABLES, name,		\
+			  SECTION_ORDER_ANY, flags)
+#endif
+
+#if defined(__ASSEMBLER__) || defined(__ASSEMBLY__)
+
+# ifndef DECLARE_SECTION_TBL
+#  define DECLARE_SECTION_TBL(section, name)				\
+  push_section_tbl(section, name,,) ;					\
+  .globl name ;								\
+name: ;									\
+  .popsection								\
+									\
+  push_section_tbl(section, name, ~,) ;					\
+  .popsection
+# endif
+
+#endif /* defined(__ASSEMBLER__) || defined(__ASSEMBLY__) */
+
+#endif /* _ASM_GENERIC_TABLES_H_ */
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 0042f30ff34b..b3a9cd7bc947 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -56,6 +56,7 @@
 
 #include <linux/export.h>
 #include <asm/sections.h>
+#include <asm/tables.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_TBL_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_TBL_ALL(SECTION_RODATA)))		\
+		*(SECTION_ALL(SECTION_RODATA))				\
 		RO_AFTER_INIT_DATA	/* Read only after init */	\
 		*(__vermagic)		/* Kernel version magic */	\
 		. = ALIGN(8);						\
@@ -434,6 +438,7 @@
 #define TEXT_TEXT							\
 		ALIGN_FUNCTION();					\
 		*(.text.hot SECTION_TEXT .text.fixup .text.unlikely)	\
+		*(SORT(SECTION_TBL_ALL(SECTION_TEXT)))			\
 		*(SECTION_REF)						\
 	MEM_KEEP(init.text)						\
 	MEM_KEEP(exit.text)						\
@@ -529,6 +534,7 @@
 /* init and exit section handling */
 #define INIT_DATA							\
 	*(SECTION_INIT_DATA)						\
+	*(SORT(SECTION_TBL_ALL(SECTION_INIT_DATA)))			\
 	MEM_DISCARD(init.data)						\
 	KERNEL_CTORS()							\
 	MCOUNT_REC()							\
@@ -551,6 +557,7 @@
 
 #define INIT_TEXT							\
 	*(SECTION_INIT)							\
+	*(SORT(SECTION_TBL_ALL(SECTION_INIT)))				\
 	*(.text.startup)						\
 	MEM_DISCARD(init.text)
 
diff --git a/include/linux/tables.h b/include/linux/tables.h
new file mode 100644
index 000000000000..89d46f4c5739
--- /dev/null
+++ b/include/linux/tables.h
@@ -0,0 +1,597 @@
+#ifndef _LINUX_LINKER_TABLES_H
+#define _LINUX_LINKER_TABLES_H
+/*
+ * Linux linker tables
+ *
+ * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
+ *
+ * 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 <linux/sections.h>
+#ifdef __KERNEL__
+# include <asm/tables.h>
+#endif /* __KERNEL__ */
+
+#ifndef __ASSEMBLY__
+
+/**
+ * DOC: Introduction
+ *
+ * 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 linker table
+ * solution provides a general linker table facility so that a new linker table
+ * can be implemented by changing C code only.
+ *
+ * Linker tables help you simplify init sequences by using ELF sections, linker
+ * build time selective sorting (disabled options get ignored), and can
+ * optionally also be used to help you avoid code bit-rot due to #ifdery
+ * collateral.
+ */
+
+/**
+ * DOC: Linker table provenance and userspace testing
+ *
+ * The Linux implementation of linker tables is derivative of iPXE linker
+ * table's solution (iPXE commit 67a10ef000cb7 [0]).  To see how this code
+ * evolved or to extend and test and use this code in userspace refer to the
+ * userspace linker-table tree [1].  This repository can be used for ease of
+ * testing of extensions and sampling of changes prior to inclusion into Linux,
+ * it is intended to be kept up to date to match Linux's solution. Contrary to
+ * iPXE's solution, which strives to force compilation of everything using
+ * linker tables, Linux's solution allows for developers to be selective over
+ * where one wishes to force compilation, this then is just an optional feature
+ * for the Linux linker table solution.
+ *
+ * [0] git://git.ipxe.org/ipxe.git
+ *
+ * [1] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linker-tables.git/
+ */
+
+/**
+ * DOC: The code bit-rot problem
+ *
+ * Overuse of C #ifdefs can be problematic for certain types of code.  Linux
+ * provides a rich array of features, but all these features take up valuable
+ * space in a kernel image. The traditional solution to this problem has been
+ * for each feature to have its own Kconfig entry and for the respective code
+ * to be wrapped around #ifdefs, allowing the feature to be compiled in only
+ * if desired.
+ *
+ * The problem with this is that over time it becomes very difficult and time
+ * consuming to compile, let alone test, all possible versions of Linux. Code
+ * that is not typically used tends to suffer from bit-rot over time. It can
+ * become difficult to predict which combinations of compile-time options will
+ * result in code that can compile and link correctly.
+ */
+
+/**
+ * DOC: Avoiding the code bit-rot problem when desirable
+ *
+ * To solve the code bit-rot problem linker tables can be used on Linux, it
+ * enables you to always force compiling of select features that one wishes to
+ * avoid bit-rot while still enabling you to disable linking feature code into
+ * the final kernel image if the features have been disabled via Kconfig.
+ * Linux's linker tables allows for developers to be selective over where one
+ * wishes to take advantage of the optional feature of forcing compilation and
+ * only linking in enabled features.
+ *
+ * To use linker tables and to optionally take advantage of avoiding code
+ * bit-rot, feature code should be implemented in separate C files, and should
+ * be designed to always be compiled -- they should not be guarded with a C
+ * code #ifdef CONFIG_FOO statements, consideration must also be taken for
+ * sub-features which depend on the main CONFIG_FOO option, as they will be
+ * disabled if they depend on CONFIG_FOO and therefore not compiled. To force
+ * compilation and only link when features are needed a new optional target
+ * table-y can be used on Makefiles, documented below.
+ *
+ * Currently only built-in features are supported, modular support is not
+ * yet supported, however you can make use of sub-features for modules
+ * if they are independent and can simply be linked into modules.
+ */
+
+/**
+ * DOC: Using target table-y and table-n
+ *
+ * Let's assume we want to always force compilation of feature FOO in the
+ * kernel but avoid linking it. When you enable the FOO feature via Kconfig
+ * you'd end up with:
+ *
+ *	#define CONFIG_FOO 1
+ *
+ * You typically would then just use this on your Makefile to selectively
+ * compile and link the feature:
+ *
+ *	obj-$(CONFIG_FOO) += foo.o
+ *
+ * You could instead optionally use the new linker table object:
+ *
+ *	table-$(CONFIG_FOO) += foo.o
+ *
+ * Alternatively, this would be the equivalent of listing:
+ *
+ *	extra += foo.o
+ *	obj-$(CONFIG_FOO) += foo.o
+ *
+ * Both are mechanisms which can be used to take advantage of forcing
+ * compilation with linker tables, however making use of table-$(CONFIG_FOO)
+ * is encouraged as it helps with annotating linker tables clearly where
+ * compilation is forced.
+ */
+
+/**
+ * DOC: Opting out of forcing compilation
+ *
+ * If you want to opt-out of forcing compilation you would use the typical
+ * obj-$(CONFIG_FOO) += foo.o and foo.o will only be compiled and linked
+ * in when enabled. Using both table-$(CONFIG_FOO) and obj-($CONFIG_FOO)
+ * will result with the feature on your binary only if you've enabled
+ * CONFIG_FOO, however using table-$(CONFIG_FOO) will always force compilation,
+ * this is why avoiding code bit-rot is an optional fature for Linux linker
+ * tables.
+ */
+
+/**
+ * DOC: How linker tables simplify inits
+ *
+ * Traditionally, we would implement features in C code as follows:
+ *
+ *	foo_init();
+ *
+ * You'd then have a foo.h which would have:
+ *
+ *	#ifdef CONFIG_FOO
+ *	#else
+ *	static inline void foo(void) { }
+ *	#endif
+ *
+ * With linker tables this is no longer necessary as your init routines would
+ * be implicit, you'd instead call:
+ *
+ *	call_init_fns();
+ *
+ * call_init_fns() would call all functions present in your init table and if
+ * and only if foo.o gets linked in, then its initialisation function will be
+ * called, whether you use obj-$(CONFIG_FOO) or table-$(CONFIG_FOO).
+ *
+ * The linker script takes care of assembling the tables for us. All of our
+ * table sections have names of the format SECTION_NAME*.tbl.NAME.N. Here
+ * SECTION_NAME is one of the standard sections in include/linux/sections.h,
+ * and NAME designates the specific use case for the linker table, the table.
+ * N is a digit decimal number used to impose an "order level" upon the tables
+ * if required. NN= (empty string) is reserved for the symbol indicating "table
+ * start", and N=~ is reserved for the symbol indicating "table end". In order
+ * for the call_init_fns() to work behind the scenes the custom linker script
+ * would need to define the beginning of the table, the end of the table, and
+ * in between it should use SORT() to give order-level effect. Now, typically
+ * such type of requirements would require custom linker script modifications
+ * but Linux's linker tables builds on top of already existing standard Linux
+ * ELF sections, each with different purposes. This lets you build and add
+ * new tables without needing custom linker script modifications. This is
+ * also done to support all architectures. All that is needed then is to
+ * ensure a respective common linker table entry is added to the shared
+ * include/asm-generic/vmlinux.lds.h. There should be a respective:
+ *
+ *	*(SORT(SECTION_TBL_ALL(SECTION_NAME)))
+ *
+ * entry for each type of supported section there. If your SECTION_NAME
+ * is not yet supported, consider adding support for it.
+ *
+ * The order-level is really only a helper, if only one order level is
+ * used, the next contributing factor to order is the order of the code
+ * in the C file, and the order of the objects in the Makefile. Using
+ * an order level then should not really be needed in most cases, its
+ * use however enables to compartamentalize code into tables where ordering
+ * through C file or through the Makefile would otherwise be very difficult
+ * or if one wanted to enable very specific initialization semantics.
+ *
+ * As an example, suppose that we want to create a "frobnicator"
+ * feature framework, and allow for several independent modules to
+ * provide frobnicating services. Then we would create a frob.h
+ * header file containing e.g.
+ *
+ *	struct frobnicator {
+ *		const char *name;
+ *		void (*frob) (void);
+ *	};
+ *
+ *	DECLARE_LINKTABLE(struct frobnicator, frobnicator_fns);
+ *
+ * Any module providing frobnicating services would look something
+ * like
+ *
+ *	#include "frob.h"
+ *	static void my_frob(void) {
+ *		... Do my frobnicating
+ *	}
+ *	LINKTABLE_INIT_DATA(frobnicator_fns, all) my_frobnicator = {
+ *		.name = "my_frob",
+ *		.frob = my_frob,
+ *	};
+ *
+ * The central frobnicator code (frob.c) would use the frobnicating
+ * modules as follows
+ *
+ *	#include "frob.h"
+ *
+ *	void frob_all(void) {
+ *		struct frob *frob;
+ *
+ *		LINKTABLE_FOR_EACH(frob, frobnicator_fns) {
+ *			pr_info("Calling frobnicator \"%s\"\n", frob->name);
+ *			frob->frob();
+ *		}
+ *	}
+ */
+
+/**
+ * DOC: Linker table helpers
+ *
+ * These are helpers for linker tables.
+ */
+
+/**
+ * LINKTABLE_ADDR_WITHIN - returns true if address is in range
+ *
+ * @tbl: linker table
+ * @addr: address to query for
+ *
+ * Returns true if the address is part of the linker table.
+ */
+#define LINKTABLE_ADDR_WITHIN(tbl, addr)				\
+	 (addr >= (unsigned long) LINUX_SECTION_START(tbl) &&		\
+          addr < (unsigned long) LINUX_SECTION_END(tbl))
+
+/**
+ * DOC: Constructing linker tables
+ *
+ * Linker tables constructors are used to build an entry into a linker table.
+ * Linker table constructors exist for each type of supported section.
+ *
+ * You have weak and regular type of link table entry constructors.
+ */
+
+/**
+ * DOC: Weak linker tables constructors
+ *
+ * The weak attribute is desirable if you want an entry you can replace at
+ * link time. A very special use case for linker tables is the first entry.
+ * A weak attribute is used for the first entry to ensure that this entry's
+ * address matches the end address of the table when the linker table is
+ * emtpy, but will also point to the first real entry of the table once not
+ * empty. When the first entry is linked in, it takes place of the first entry.
+ */
+
+/**
+ * LINKTABLE_WEAK - Constructs a weak linker table entry for data
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Constructs a weak linker table for data.
+ */
+#define LINKTABLE_WEAK(name, level)					\
+	      __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     weak,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_DATA, name, level))))
+
+/**
+ * LINKTABLE_TEXT_WEAK - Constructs a weak linker table entry for execution
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Constructs a weak linker table for code execution. These will be
+ * read-only.
+ */
+#define LINKTABLE_TEXT_WEAK(name, level)				\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     weak,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_TEXT, name, level))))
+
+/**
+ * LINKTABLE_RO_WEAK - Constructs a weak read-only linker table entry
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Constructs a weak linker table which only requires read-only access.
+ */
+#define LINKTABLE_RO_WEAK(name, level)					\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     weak,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_RODATA, name, level))))
+
+/**
+ * LINKTABLE_INIT_WEAK - Constructs a weak linker table entry for init code
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Constructs a weak linker table for execution. use at init.
+ */
+#define LINKTABLE_INIT_WEAK(name, level)				\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     weak,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_INIT, name, level))))
+
+/**
+ * LINKTABLE_INIT_DATA_WEAK - Constructs a weak linker table entry for initdata
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Constructs a weak linker table for data during init.
+ */
+#define LINKTABLE_INIT_DATA_WEAK(name, level)				\
+	      __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     weak,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_INIT_DATA, name, level))))
+
+/**
+ * DOC: Regular linker linker table constructors
+ *
+ * Regular constructors are expected to be used for valid linker table entries.
+ * Valid uses of weak entries other than the beginning and is currently
+ * untested but should in theory work.
+ */
+
+/**
+ * LINKTABLE - Declares a data linker table entry
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Declares a data linker table entry. These are read-write.
+ */
+#define LINKTABLE(name, level)						\
+	      __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_DATA, name, level))))
+
+/**
+ * LINKTABLE_TEXT - Declares a linker table entry for execution
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Declares a linker table to be used for execution.
+ */
+#define LINKTABLE_TEXT(name, level)					\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_TEXT, name, level))))
+
+/**
+ * LINKTABLE_RO - Declares a read-only linker table entry.
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Declares a linker table which only requires read-only access.
+ */
+#define LINKTABLE_RO(name, level)					\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_RODATA, name, level))))
+
+/**
+ * LINKTABLE_INIT - Declares a linker table entry to be used on init.
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Declares a linker table entry for execution use during init.
+ */
+#define LINKTABLE_INIT(name, level)					\
+	const __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     __aligned__(LINUX_SECTION_ALIGN_FUNC),	\
+			     section(SECTION_TBL(SECTION_INIT, name, level))))
+
+/**
+ * LINKTABLE_INIT_DATA - Declares a linker table entry to be used on init data.
+ *
+ * @name: linker table name
+ * @level: order level
+ *
+ * Declares a linker table entry for data during init.
+ */
+#define LINKTABLE_INIT_DATA(name, level)					\
+	      __typeof__(name[0])					\
+	      __attribute__((used,					\
+			     __aligned__(LINUX_SECTION_ALIGNMENT(name)),\
+			     section(SECTION_TBL(SECTION_INIT_DATA, name, level))))
+
+/**
+ * DOC: Declaring Linker tables
+ *
+ * Declarers are used to help code access the linker tables. Typically
+ * header files for subsystems would declare the linker tables to enable
+ * easy access to add new entries, and to iterate over the list of table.
+ */
+
+
+/**
+ * DECLARE_LINKTABLE - Declares a data linker table entry
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Declares a data linker table entry.
+ */
+#define DECLARE_LINKTABLE(type, name)					\
+	DECLARE_LINUX_SECTION(type, name)
+
+/**
+ * DECLARE_LINKTABLE_RO - Declares a read-only linker table entry
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Declares a read-only linker table entry.
+ */
+#define DECLARE_LINKTABLE_RO(type, name)				\
+	DECLARE_LINUX_SECTION_RO(type, name)
+
+/**
+ * DOC: Defining Linker tables
+ *
+ * Linker tables are defined in the code that takes ownership over
+ * the linker table. This is typically done in the same code that is in
+ * charge of iterating over the linker table as well.
+ */
+
+/**
+ * DEFINE_LINKTABLE - Defines a linker table for data
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Defines a linker table which used for data.
+ */
+#define DEFINE_LINKTABLE(type, name)					\
+	DECLARE_LINKTABLE(type, name);					\
+	LINKTABLE_WEAK(name, ) VMLINUX_SYMBOL(name)[0] = {};		\
+	LINKTABLE(name, ~) VMLINUX_SYMBOL(name##__end)[0] = {};
+
+/**
+ * DEFINE_LINKTABLE_TEXT - Declares linker table entry for exectuion
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Declares a linker table entry for execution.
+ */
+#define DEFINE_LINKTABLE_TEXT(type, name)				\
+	DECLARE_LINKTABLE_RO(type, name);				\
+	LINKTABLE_TEXT_WEAK(name, ) VMLINUX_SYMBOL(name)[0] = {};	\
+	LINKTABLE_TEXT(name, ~) VMLINUX_SYMBOL(name##__end)[0] = {};
+
+/**
+ * DEFINE_LINKTABLE_RO - Defines a read-only linker table
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Defines a linker table which we know only requires read-only access.
+ */
+#define DEFINE_LINKTABLE_RO(type, name)					\
+	DECLARE_LINKTABLE_RO(type, name);				\
+	LINKTABLE_RO_WEAK(name, ) VMLINUX_SYMBOL(name)[0] = {};		\
+	LINKTABLE_RO(name, ~) VMLINUX_SYMBOL(name##__end)[0] = {};
+
+/**
+ * DEFINE_LINKTABLE_INIT - Defines an init time linker table for execution
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Defines a linker table. If you are adding a new type you should
+ * enable CONFIG_DEBUG_SECTION_MISMATCH and ensure routines that make
+ * use of the linker tables get a respective __ref tag.
+ */
+#define DEFINE_LINKTABLE_INIT(type, name)				\
+	DECLARE_LINKTABLE(type, name);					\
+	LINKTABLE_INIT_WEAK(name, ) VMLINUX_SYMBOL(name)[0] = {};	\
+	LINKTABLE_INIT(name, ~) VMLINUX_SYMBOL(name##__end)[0] = {};
+
+/**
+ * DEFINE_LINKTABLE_INIT_DATA - Defines an init time linker table for data
+ *
+ * @type: data type
+ * @name: table name
+ *
+ * Defines a linker table for init data. If you are adding a new type you
+ * should enable CONFIG_DEBUG_SECTION_MISMATCH and ensure routines that make
+ * use of the linker tables get a respective __ref tag.
+ */
+#define DEFINE_LINKTABLE_INIT_DATA(type, name)				\
+	DECLARE_LINKTABLE(type, name);					\
+	LINKTABLE_INIT_DATA_WEAK(name, ) VMLINUX_SYMBOL(name)[0] = {};	\
+	LINKTABLE_INIT_DATA(name, ~) VMLINUX_SYMBOL(name##__end)[0] = {};
+
+/**
+ * DOC: Iterating over Linker tables
+ *
+ * To make use of the linker tables you want to be able to iterate over
+ * them. This section documents the different iterators available.
+ */
+
+/**
+ * LINKTABLE_FOR_EACH - iterate through all entries within a linker table
+ *
+ * @pointer: entry pointer
+ * @tbl: linker table
+ *
+ * Example usage:
+ *
+ *   struct frobnicator *frob;
+ *
+ *   LINKTABLE_FOR_EACH(frob, frobnicator_fns) {
+ *     ...
+ *   }
+ */
+
+#define LINKTABLE_FOR_EACH(pointer, tbl)				\
+	for (pointer = LINUX_SECTION_START(tbl);			\
+	     pointer < LINUX_SECTION_END(tbl);				\
+	     pointer++)
+
+/**
+ * LINKTABLE_RUN_ALL - iterate and run through all entries on a linker table
+ *
+ * @tbl: linker table
+ * @func: structure name for the function name we want to call.
+ * @args...: arguments to pass to func
+ *
+ * Example usage:
+ *
+ *   LINKTABLE_RUN_ALL(frobnicator_fns, some_run,);
+ */
+#define LINKTABLE_RUN_ALL(tbl, func, args...)				\
+do {									\
+	size_t i;							\
+	for (i = 0; i < LINUX_SECTION_SIZE(tbl); i++)			\
+		(tbl[i]).func (args);					\
+} while (0);
+
+/**
+ * LINKTABLE_RUN_ERR - run each linker table entry func and return error if any
+ *
+ * @tbl: linker table
+ * @func: structure name for the function name we want to call.
+ * @args...: arguments to pass to func
+ *
+ * Example usage:
+ *
+ *   unsigned int err = LINKTABLE_RUN_ERR(frobnicator_fns, some_run,);
+ */
+#define LINKTABLE_RUN_ERR(tbl, func, args...)				\
+({									\
+	size_t i;							\
+	int err = 0;							\
+	for (i = 0; !err && i < LINUX_SECTION_SIZE(tbl); i++)		\
+		err = (tbl[i]).func (args);				\
+		err; \
+})
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _LINUX_LINKER_TABLES_H */
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 11602e5efb3b..002857fe8d0d 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -91,7 +91,7 @@ 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) $(table-y)) \
 	 $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \
 	 $(subdir-ym) $(always)
 	@:
@@ -326,7 +326,7 @@ $(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 += $(extra-y) $(table-y) $(MAKECMDGOALS) $(always)
 
 # Linker scripts preprocessor (.lds.S -> .lds)
 # ---------------------------------------------------------------------------
diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
index 50616ea25131..bdc29810dae5 100644
--- a/scripts/Makefile.clean
+++ b/scripts/Makefile.clean
@@ -36,6 +36,7 @@ subdir-ymn	:= $(addprefix $(obj)/,$(subdir-ymn))
 # directory
 
 __clean-files	:= $(extra-y) $(extra-m) $(extra-)       \
+		   $(table-y) $(table-m) $(table-)       \
 		   $(always) $(targets) $(clean-files)   \
 		   $(host-progs)                         \
 		   $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 0a07f9014944..494f215ebaa4 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -12,6 +12,16 @@ export KBUILD_SUBDIR_CCFLAGS := $(KBUILD_SUBDIR_CCFLAGS) $(subdir-ccflags-y)
 # Figure out what we need to build from the various variables
 # ===========================================================================
 
+# Linker tables objects always wish to be built to avoid bit-rot in
+# code, but only linked in *iff* they were enabled. We accomplish this
+# using pegging linker table objects into extra-y, which forces
+# compilation and then using the respective table-y and table-m as
+# as hints for things we do want enabled. Objects which we want to
+# avoid linking in will be in table-, not table-y and table-m.
+extra-y += $(table-)
+obj-m += $(table-m)
+obj-y += $(table-y)
+
 # When an object is listed to be built compiled-in and modular,
 # only build the compiled-in version
 
@@ -72,6 +82,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))
+table-y		:= $(addprefix $(obj)/,$(table-y))
+table-m		:= $(addprefix $(obj)/,$(table-m))
 always		:= $(addprefix $(obj)/,$(always))
 targets		:= $(addprefix $(obj)/,$(targets))
 modorder	:= $(addprefix $(obj)/,$(modorder))
diff --git a/tools/include/linux/sections.h b/tools/include/linux/sections.h
new file mode 100644
index 000000000000..cc6f07f11583
--- /dev/null
+++ b/tools/include/linux/sections.h
@@ -0,0 +1,13 @@
+#ifndef _TOOLS_LINUX_SECTIONS_H_
+
+/* Mostly a copy of what we need only */
+
+#define SECTION_INIT			.init.text
+#define SECTION_RODATA			.rodata
+
+#define ___SECTION_TBL_STR(section, name)				\
+	#section ".tbl." #name
+#define SECTION_TBL_ALL_STR(section)					\
+	___SECTION_TBL_STR(section, *)
+
+#endif /* _TOOLS_LINUX_SECTIONS_H_ */
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 08/13] firmware/Makefile: force recompilation if makefile changes
  2016-07-22 21:24 ` Luis R. Rodriguez
  (?)
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: gnomes, linux-ia64, jkosina, benh, ming.lei, linux,
	platform-driver-x86, paul.gortmaker, sparclinux, linux-arch,
	xen-devel, linux-sh, x86, fontana, linux-arm-kernel,
	catalin.marinas, dvhart, dwmw2, pali.rohar, keescook, arnd,
	will.deacon, rusty, rostedt, christopher.denicolo, ak,
	ciaran.farrell, jpoimboe, andriy.shevchenko, mcb30, linux-kbuild,
	alan, jgross, pebolle, tony.luck, ananth, gregk

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 firmware/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/firmware/Makefile b/firmware/Makefile
index e297e1b52636..fa3e81c2a97b 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -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,%,$@))
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 08/13] firmware/Makefile: force recompilation if makefile changes
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: gnomes, linux-ia64, jkosina, benh, ming.lei, linux,
	platform-driver-x86, paul.gortmaker, sparclinux, linux-arch,
	xen-devel, linux-sh, x86, fontana, linux-arm-kernel,
	catalin.marinas, dvhart, dwmw2, pali.rohar, keescook, arnd,
	will.deacon, rusty, rostedt, christopher.denicolo, ak,
	ciaran.farrell, jpoimboe, andriy.shevchenko, mcb30, linux-kbuild,
	alan, jgross, pebolle, tony.luck, ananth, gregk

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 firmware/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/firmware/Makefile b/firmware/Makefile
index e297e1b52636..fa3e81c2a97b 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -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,%,$@))
-- 
2.8.4


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 08/13] firmware/Makefile: force recompilation if makefile changes
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe, Luis R. Rodriguez

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 firmware/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)

diff --git a/firmware/Makefile b/firmware/Makefile
index e297e1b52636..fa3e81c2a97b 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -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,%,$@))
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 09/13] firmware: port built-in section to linker table
  2016-07-22 21:24 ` Luis R. Rodriguez
  (?)
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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.

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 arch/x86/kernel/cpu/microcode/core.c |  8 ++++----
 drivers/base/firmware_class.c        | 12 ++++++------
 firmware/Makefile                    |  4 +++-
 include/asm-generic/vmlinux.lds.h    |  7 -------
 4 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
index df04b2d033f6..3e7c08d99601 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -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;
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 22d1760a4278..8fbf03c3e4c2 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -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;
 
diff --git a/firmware/Makefile b/firmware/Makefile
index fa3e81c2a97b..32304a227f09 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -155,6 +155,8 @@ 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/sections.h>"			>>$@;\
+		  echo "\#include <asm/tables.h>"			>>$@;\
 		  echo "    .section .rodata"				>>$@;\
 		  echo "    .p2align $${ASM_ALIGN}"			>>$@;\
 		  echo "_fw_$${FWSTR}_bin:"				>>$@;\
@@ -164,7 +166,7 @@ quiet_cmd_fwbin = MK_FW   $@
 		  echo "    .p2align $${ASM_ALIGN}"			>>$@;\
 		  echo "_fw_$${FWSTR}_name:"				>>$@;\
 		  echo "    .string \"$$FWNAME\""			>>$@;\
-		  echo "    .section .builtin_fw,\"a\",$${PROGBITS}"	>>$@;\
+		  echo "    section_tbl_asmtype(SECTION_RODATA, builtin_fw, SECTION_ORDER_ANY, a,$${PROGBITS})"	>>$@;\
 		  echo "    .p2align $${ASM_ALIGN}"			>>$@;\
 		  echo "    $${ASM_WORD} _fw_$${FWSTR}_name"		>>$@;\
 		  echo "    $${ASM_WORD} _fw_$${FWSTR}_bin"		>>$@;\
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index b3a9cd7bc947..8e31a4454841 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -313,13 +313,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 */			\
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 09/13] firmware: port built-in section to linker table
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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.

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 arch/x86/kernel/cpu/microcode/core.c |  8 ++++----
 drivers/base/firmware_class.c        | 12 ++++++------
 firmware/Makefile                    |  4 +++-
 include/asm-generic/vmlinux.lds.h    |  7 -------
 4 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
index df04b2d033f6..3e7c08d99601 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -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;
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 22d1760a4278..8fbf03c3e4c2 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -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;
 
diff --git a/firmware/Makefile b/firmware/Makefile
index fa3e81c2a97b..32304a227f09 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -155,6 +155,8 @@ 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/sections.h>"			>>$@;\
+		  echo "\#include <asm/tables.h>"			>>$@;\
 		  echo "    .section .rodata"				>>$@;\
 		  echo "    .p2align $${ASM_ALIGN}"			>>$@;\
 		  echo "_fw_$${FWSTR}_bin:"				>>$@;\
@@ -164,7 +166,7 @@ quiet_cmd_fwbin = MK_FW   $@
 		  echo "    .p2align $${ASM_ALIGN}"			>>$@;\
 		  echo "_fw_$${FWSTR}_name:"				>>$@;\
 		  echo "    .string \"$$FWNAME\""			>>$@;\
-		  echo "    .section .builtin_fw,\"a\",$${PROGBITS}"	>>$@;\
+		  echo "    section_tbl_asmtype(SECTION_RODATA, builtin_fw, SECTION_ORDER_ANY, a,$${PROGBITS})"	>>$@;\
 		  echo "    .p2align $${ASM_ALIGN}"			>>$@;\
 		  echo "    $${ASM_WORD} _fw_$${FWSTR}_name"		>>$@;\
 		  echo "    $${ASM_WORD} _fw_$${FWSTR}_bin"		>>$@;\
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index b3a9cd7bc947..8e31a4454841 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -313,13 +313,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 */			\
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 09/13] firmware: port built-in section to linker table
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe, Luis R. Rodriguez

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.

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 arch/x86/kernel/cpu/microcode/core.c |  8 ++++----
 drivers/base/firmware_class.c        | 12 ++++++------
 firmware/Makefile                    |  4 +++-
 include/asm-generic/vmlinux.lds.h    |  7 -------
 4 files changed, 13 insertions(+), 18 deletions(-)

diff --git a/arch/x86/kernel/cpu/microcode/core.c b/arch/x86/kernel/cpu/microcode/core.c
index df04b2d033f6..3e7c08d99601 100644
--- a/arch/x86/kernel/cpu/microcode/core.c
+++ b/arch/x86/kernel/cpu/microcode/core.c
@@ -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;
diff --git a/drivers/base/firmware_class.c b/drivers/base/firmware_class.c
index 22d1760a4278..8fbf03c3e4c2 100644
--- a/drivers/base/firmware_class.c
+++ b/drivers/base/firmware_class.c
@@ -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;
 
diff --git a/firmware/Makefile b/firmware/Makefile
index fa3e81c2a97b..32304a227f09 100644
--- a/firmware/Makefile
+++ b/firmware/Makefile
@@ -155,6 +155,8 @@ 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/sections.h>"			>>$@;\
+		  echo "\#include <asm/tables.h>"			>>$@;\
 		  echo "    .section .rodata"				>>$@;\
 		  echo "    .p2align $${ASM_ALIGN}"			>>$@;\
 		  echo "_fw_$${FWSTR}_bin:"				>>$@;\
@@ -164,7 +166,7 @@ quiet_cmd_fwbin = MK_FW   $@
 		  echo "    .p2align $${ASM_ALIGN}"			>>$@;\
 		  echo "_fw_$${FWSTR}_name:"				>>$@;\
 		  echo "    .string \"$$FWNAME\""			>>$@;\
-		  echo "    .section .builtin_fw,\"a\",$${PROGBITS}"	>>$@;\
+		  echo "    section_tbl_asmtype(SECTION_RODATA, builtin_fw, SECTION_ORDER_ANY, a,$${PROGBITS})"	>>$@;\
 		  echo "    .p2align $${ASM_ALIGN}"			>>$@;\
 		  echo "    $${ASM_WORD} _fw_$${FWSTR}_name"		>>$@;\
 		  echo "    $${ASM_WORD} _fw_$${FWSTR}_bin"		>>$@;\
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index b3a9cd7bc947..8e31a4454841 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -313,13 +313,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 */			\
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 10/13] jump_label: port __jump_table to linker tables
  2016-07-22 21:24 ` Luis R. Rodriguez
  (?)
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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 juse 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

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 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            | 10 ++++++----
 kernel/jump_label.c                   | 17 ++++++++++-------
 scripts/module-common.lds.S           |  5 +++++
 tools/objtool/special.c               |  8 +++++++-
 12 files changed, 59 insertions(+), 33 deletions(-)

diff --git a/arch/arm/include/asm/jump_label.h b/arch/arm/include/asm/jump_label.h
index 34f7b6980d21..960135a7b88e 100644
--- a/arch/arm/include/asm/jump_label.h
+++ b/arch/arm/include/asm/jump_label.h
@@ -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);
diff --git a/arch/arm64/include/asm/jump_label.h b/arch/arm64/include/asm/jump_label.h
index 1b5e0e843c3a..aa52cd2607e3 100644
--- a/arch/arm64/include/asm/jump_label.h
+++ b/arch/arm64/include/asm/jump_label.h
@@ -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"
diff --git a/arch/mips/include/asm/jump_label.h b/arch/mips/include/asm/jump_label.h
index e77672539e8e..78e70cb98592 100644
--- a/arch/mips/include/asm/jump_label.h
+++ b/arch/mips/include/asm/jump_label.h
@@ -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);
diff --git a/arch/powerpc/include/asm/jump_label.h b/arch/powerpc/include/asm/jump_label.h
index 9af103a23975..bf68a8766773 100644
--- a/arch/powerpc/include/asm/jump_label.h
+++ b/arch/powerpc/include/asm/jump_label.h
@@ -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\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]\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
diff --git a/arch/s390/include/asm/jump_label.h b/arch/s390/include/asm/jump_label.h
index 9be198f5ee79..17f02aec4644 100644
--- a/arch/s390/include/asm/jump_label.h
+++ b/arch/s390/include/asm/jump_label.h
@@ -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"
diff --git a/arch/sparc/include/asm/jump_label.h b/arch/sparc/include/asm/jump_label.h
index 62d0354d1727..dde1275233f7 100644
--- a/arch/sparc/include/asm/jump_label.h
+++ b/arch/sparc/include/asm/jump_label.h
@@ -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"
diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_label.h
index adc54c12cbd1..d25fafa3df4b 100644
--- a/arch/x86/include/asm/jump_label.h
+++ b/arch/x86/include/asm/jump_label.h
@@ -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
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 8e31a4454841..e186432a82e6 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -210,10 +210,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)                                                    \
diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h
index 661af564fae8..e6acdd8cd62b 100644
--- a/include/linux/jump_label.h
+++ b/include/linux/jump_label.h
@@ -130,8 +130,10 @@ 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[];
+#ifndef __KERNEL__
+ #include <linux/tables.h>
+ DECLARE_LINKTABLE(struct jump_entry, __jump_table);
+#endif /* __KERNEL__ */
 
 extern void jump_label_init(void);
 extern void jump_label_lock(void);
@@ -384,6 +386,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 */
diff --git a/kernel/jump_label.c b/kernel/jump_label.c
index f19aa02a8f48..72dd2026ea3f 100644
--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -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;
 
@@ -289,9 +290,10 @@ void __init jump_label_init(void)
 	BUILD_BUG_ON((int)ATOMIC_INIT(1) != 1);
 
 	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 */
@@ -533,8 +535,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;
@@ -547,7 +550,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;
diff --git a/scripts/module-common.lds.S b/scripts/module-common.lds.S
index 73a2c7da0e55..d51140103ece 100644
--- a/scripts/module-common.lds.S
+++ b/scripts/module-common.lds.S
@@ -3,6 +3,10 @@
  * Archs are free to supply their own linker scripts.  ld will
  * combine them automatically.
  */
+
+#include <asm/sections.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) }
diff --git a/tools/objtool/special.c b/tools/objtool/special.c
index bff8abb3a4aa..f0ad369f994b 100644
--- a/tools/objtool/special.c
+++ b/tools/objtool/special.c
@@ -26,6 +26,10 @@
 #include "special.h"
 #include "warn.h"
 
+#include "../../include/asm-generic/sections.h"
+#include "../../include/asm-generic/tables.h"
+#include "../../include/linux/stringify.h"
+
 #define EX_ENTRY_SIZE		12
 #define EX_ORIG_OFFSET		0
 #define EX_NEW_OFFSET		4
@@ -63,7 +67,9 @@ struct special_entry entries[] = {
 		.feature = ALT_FEATURE_OFFSET,
 	},
 	{
-		.sec = "__jump_table",
+		.sec = __stringify(SECTION_TBL(SECTION_DATA,
+				               __jump_table,
+					       SECTION_ORDER_ANY)),
 		.jump_or_nop = true,
 		.size = JUMP_ENTRY_SIZE,
 		.orig = JUMP_ORIG_OFFSET,
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 10/13] jump_label: port __jump_table to linker tables
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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 juse 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

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 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            | 10 ++++++----
 kernel/jump_label.c                   | 17 ++++++++++-------
 scripts/module-common.lds.S           |  5 +++++
 tools/objtool/special.c               |  8 +++++++-
 12 files changed, 59 insertions(+), 33 deletions(-)

diff --git a/arch/arm/include/asm/jump_label.h b/arch/arm/include/asm/jump_label.h
index 34f7b6980d21..960135a7b88e 100644
--- a/arch/arm/include/asm/jump_label.h
+++ b/arch/arm/include/asm/jump_label.h
@@ -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);
diff --git a/arch/arm64/include/asm/jump_label.h b/arch/arm64/include/asm/jump_label.h
index 1b5e0e843c3a..aa52cd2607e3 100644
--- a/arch/arm64/include/asm/jump_label.h
+++ b/arch/arm64/include/asm/jump_label.h
@@ -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"
diff --git a/arch/mips/include/asm/jump_label.h b/arch/mips/include/asm/jump_label.h
index e77672539e8e..78e70cb98592 100644
--- a/arch/mips/include/asm/jump_label.h
+++ b/arch/mips/include/asm/jump_label.h
@@ -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);
diff --git a/arch/powerpc/include/asm/jump_label.h b/arch/powerpc/include/asm/jump_label.h
index 9af103a23975..bf68a8766773 100644
--- a/arch/powerpc/include/asm/jump_label.h
+++ b/arch/powerpc/include/asm/jump_label.h
@@ -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\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]\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
diff --git a/arch/s390/include/asm/jump_label.h b/arch/s390/include/asm/jump_label.h
index 9be198f5ee79..17f02aec4644 100644
--- a/arch/s390/include/asm/jump_label.h
+++ b/arch/s390/include/asm/jump_label.h
@@ -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"
diff --git a/arch/sparc/include/asm/jump_label.h b/arch/sparc/include/asm/jump_label.h
index 62d0354d1727..dde1275233f7 100644
--- a/arch/sparc/include/asm/jump_label.h
+++ b/arch/sparc/include/asm/jump_label.h
@@ -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"
diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_label.h
index adc54c12cbd1..d25fafa3df4b 100644
--- a/arch/x86/include/asm/jump_label.h
+++ b/arch/x86/include/asm/jump_label.h
@@ -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
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 8e31a4454841..e186432a82e6 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -210,10 +210,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)                                                    \
diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h
index 661af564fae8..e6acdd8cd62b 100644
--- a/include/linux/jump_label.h
+++ b/include/linux/jump_label.h
@@ -130,8 +130,10 @@ 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[];
+#ifndef __KERNEL__
+ #include <linux/tables.h>
+ DECLARE_LINKTABLE(struct jump_entry, __jump_table);
+#endif /* __KERNEL__ */
 
 extern void jump_label_init(void);
 extern void jump_label_lock(void);
@@ -384,6 +386,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 */
diff --git a/kernel/jump_label.c b/kernel/jump_label.c
index f19aa02a8f48..72dd2026ea3f 100644
--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -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;
 
@@ -289,9 +290,10 @@ void __init jump_label_init(void)
 	BUILD_BUG_ON((int)ATOMIC_INIT(1) != 1);
 
 	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 */
@@ -533,8 +535,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;
@@ -547,7 +550,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;
diff --git a/scripts/module-common.lds.S b/scripts/module-common.lds.S
index 73a2c7da0e55..d51140103ece 100644
--- a/scripts/module-common.lds.S
+++ b/scripts/module-common.lds.S
@@ -3,6 +3,10 @@
  * Archs are free to supply their own linker scripts.  ld will
  * combine them automatically.
  */
+
+#include <asm/sections.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) }
diff --git a/tools/objtool/special.c b/tools/objtool/special.c
index bff8abb3a4aa..f0ad369f994b 100644
--- a/tools/objtool/special.c
+++ b/tools/objtool/special.c
@@ -26,6 +26,10 @@
 #include "special.h"
 #include "warn.h"
 
+#include "../../include/asm-generic/sections.h"
+#include "../../include/asm-generic/tables.h"
+#include "../../include/linux/stringify.h"
+
 #define EX_ENTRY_SIZE		12
 #define EX_ORIG_OFFSET		0
 #define EX_NEW_OFFSET		4
@@ -63,7 +67,9 @@ struct special_entry entries[] = {
 		.feature = ALT_FEATURE_OFFSET,
 	},
 	{
-		.sec = "__jump_table",
+		.sec = __stringify(SECTION_TBL(SECTION_DATA,
+				               __jump_table,
+					       SECTION_ORDER_ANY)),
 		.jump_or_nop = true,
 		.size = JUMP_ENTRY_SIZE,
 		.orig = JUMP_ORIG_OFFSET,
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 10/13] jump_label: port __jump_table to linker tables
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe, Luis R. Rodriguez

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 juse 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

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 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            | 10 ++++++----
 kernel/jump_label.c                   | 17 ++++++++++-------
 scripts/module-common.lds.S           |  5 +++++
 tools/objtool/special.c               |  8 +++++++-
 12 files changed, 59 insertions(+), 33 deletions(-)

diff --git a/arch/arm/include/asm/jump_label.h b/arch/arm/include/asm/jump_label.h
index 34f7b6980d21..960135a7b88e 100644
--- a/arch/arm/include/asm/jump_label.h
+++ b/arch/arm/include/asm/jump_label.h
@@ -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);
diff --git a/arch/arm64/include/asm/jump_label.h b/arch/arm64/include/asm/jump_label.h
index 1b5e0e843c3a..aa52cd2607e3 100644
--- a/arch/arm64/include/asm/jump_label.h
+++ b/arch/arm64/include/asm/jump_label.h
@@ -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"
diff --git a/arch/mips/include/asm/jump_label.h b/arch/mips/include/asm/jump_label.h
index e77672539e8e..78e70cb98592 100644
--- a/arch/mips/include/asm/jump_label.h
+++ b/arch/mips/include/asm/jump_label.h
@@ -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);
diff --git a/arch/powerpc/include/asm/jump_label.h b/arch/powerpc/include/asm/jump_label.h
index 9af103a23975..bf68a8766773 100644
--- a/arch/powerpc/include/asm/jump_label.h
+++ b/arch/powerpc/include/asm/jump_label.h
@@ -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\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]\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
diff --git a/arch/s390/include/asm/jump_label.h b/arch/s390/include/asm/jump_label.h
index 9be198f5ee79..17f02aec4644 100644
--- a/arch/s390/include/asm/jump_label.h
+++ b/arch/s390/include/asm/jump_label.h
@@ -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"
diff --git a/arch/sparc/include/asm/jump_label.h b/arch/sparc/include/asm/jump_label.h
index 62d0354d1727..dde1275233f7 100644
--- a/arch/sparc/include/asm/jump_label.h
+++ b/arch/sparc/include/asm/jump_label.h
@@ -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"
diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_label.h
index adc54c12cbd1..d25fafa3df4b 100644
--- a/arch/x86/include/asm/jump_label.h
+++ b/arch/x86/include/asm/jump_label.h
@@ -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
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 8e31a4454841..e186432a82e6 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -210,10 +210,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)                                                    \
diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h
index 661af564fae8..e6acdd8cd62b 100644
--- a/include/linux/jump_label.h
+++ b/include/linux/jump_label.h
@@ -130,8 +130,10 @@ 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[];
+#ifndef __KERNEL__
+ #include <linux/tables.h>
+ DECLARE_LINKTABLE(struct jump_entry, __jump_table);
+#endif /* __KERNEL__ */
 
 extern void jump_label_init(void);
 extern void jump_label_lock(void);
@@ -384,6 +386,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 */
diff --git a/kernel/jump_label.c b/kernel/jump_label.c
index f19aa02a8f48..72dd2026ea3f 100644
--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -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;
 
@@ -289,9 +290,10 @@ void __init jump_label_init(void)
 	BUILD_BUG_ON((int)ATOMIC_INIT(1) != 1);
 
 	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 */
@@ -533,8 +535,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;
@@ -547,7 +550,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;
diff --git a/scripts/module-common.lds.S b/scripts/module-common.lds.S
index 73a2c7da0e55..d51140103ece 100644
--- a/scripts/module-common.lds.S
+++ b/scripts/module-common.lds.S
@@ -3,6 +3,10 @@
  * Archs are free to supply their own linker scripts.  ld will
  * combine them automatically.
  */
+
+#include <asm/sections.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) }
diff --git a/tools/objtool/special.c b/tools/objtool/special.c
index bff8abb3a4aa..f0ad369f994b 100644
--- a/tools/objtool/special.c
+++ b/tools/objtool/special.c
@@ -26,6 +26,10 @@
 #include "special.h"
 #include "warn.h"
 
+#include "../../include/asm-generic/sections.h"
+#include "../../include/asm-generic/tables.h"
+#include "../../include/linux/stringify.h"
+
 #define EX_ENTRY_SIZE		12
 #define EX_ORIG_OFFSET		0
 #define EX_NEW_OFFSET		4
@@ -63,7 +67,9 @@ struct special_entry entries[] = {
 		.feature = ALT_FEATURE_OFFSET,
 	},
 	{
-		.sec = "__jump_table",
+		.sec = __stringify(SECTION_TBL(SECTION_DATA,
+				               __jump_table,
+					       SECTION_ORDER_ANY)),
 		.jump_or_nop = true,
 		.size = JUMP_ENTRY_SIZE,
 		.orig = JUMP_ORIG_OFFSET,
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 11/13] dynamic_debug: port to use linker tables
  2016-07-22 21:24 ` Luis R. Rodriguez
  (?)
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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.

v3: added modular support
v2: introduced this patch into the series

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 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(-)

diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index e186432a82e6..8048242b6a76 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -209,11 +209,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()							\
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 546d68057e3b..a52618a77b09 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -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__,				\
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index da796e2dc4f5..f0060c84c654 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -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') {
diff --git a/scripts/module-common.lds.S b/scripts/module-common.lds.S
index d51140103ece..fec57aa5f4f1 100644
--- a/scripts/module-common.lds.S
+++ b/scripts/module-common.lds.S
@@ -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) }
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 11/13] dynamic_debug: port to use linker tables
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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.

v3: added modular support
v2: introduced this patch into the series

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 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(-)

diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index e186432a82e6..8048242b6a76 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -209,11 +209,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()							\
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 546d68057e3b..a52618a77b09 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -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__,				\
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index da796e2dc4f5..f0060c84c654 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -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') {
diff --git a/scripts/module-common.lds.S b/scripts/module-common.lds.S
index d51140103ece..fec57aa5f4f1 100644
--- a/scripts/module-common.lds.S
+++ b/scripts/module-common.lds.S
@@ -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) }
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 11/13] dynamic_debug: port to use linker tables
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe, Luis R. Rodriguez

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.

v3: added modular support
v2: introduced this patch into the series

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 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(-)

diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index e186432a82e6..8048242b6a76 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -209,11 +209,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()							\
diff --git a/include/linux/dynamic_debug.h b/include/linux/dynamic_debug.h
index 546d68057e3b..a52618a77b09 100644
--- a/include/linux/dynamic_debug.h
+++ b/include/linux/dynamic_debug.h
@@ -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__,				\
diff --git a/lib/dynamic_debug.c b/lib/dynamic_debug.c
index da796e2dc4f5..f0060c84c654 100644
--- a/lib/dynamic_debug.c
+++ b/lib/dynamic_debug.c
@@ -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') {
diff --git a/scripts/module-common.lds.S b/scripts/module-common.lds.S
index d51140103ece..fec57aa5f4f1 100644
--- a/scripts/module-common.lds.S
+++ b/scripts/module-common.lds.S
@@ -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) }
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 12/13] kprobes: port .kprobes.text to section range
  2016-07-22 21:24 ` Luis R. Rodriguez
  (?)
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 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/avr32/kernel/entry-avr32b.S     |  5 +++--
 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                |  5 +++--
 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            |  2 +-
 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/sections.h       |  2 --
 include/asm-generic/vmlinux.lds.h    |  6 ------
 include/linux/compiler.h             |  2 +-
 include/linux/kprobes.h              |  3 +++
 kernel/kprobes.c                     |  6 ++++--
 scripts/Makefile                     |  1 +
 scripts/mod/Makefile                 |  2 ++
 scripts/mod/modpost.c                |  8 +++++++-
 scripts/recordmcount.c               |  7 ++++++-
 scripts/recordmcount.pl              |  2 +-
 42 files changed, 53 insertions(+), 58 deletions(-)

diff --git a/arch/arc/kernel/vmlinux.lds.S b/arch/arc/kernel/vmlinux.lds.S
index 894e696bddaa..52f23df2b9b6 100644
--- a/arch/arc/kernel/vmlinux.lds.S
+++ b/arch/arc/kernel/vmlinux.lds.S
@@ -98,7 +98,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		*(.fixup)
 		*(.gnu.warning)
 	}
diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
index bc5f50799d75..e56ba05eae34 100644
--- a/arch/arm/kernel/entry-armv.S
+++ b/arch/arm/kernel/entry-armv.S
@@ -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
+	section_rng_asmtype(SECTION_TEXT, kprobes, ax, %progbits)
 #else
 	.text
 #endif
diff --git a/arch/arm/kernel/vmlinux-xip.lds.S b/arch/arm/kernel/vmlinux-xip.lds.S
index cba1ec899a69..3aea8834e3d2 100644
--- a/arch/arm/kernel/vmlinux-xip.lds.S
+++ b/arch/arm/kernel/vmlinux-xip.lds.S
@@ -99,7 +99,6 @@ SECTIONS
 			TEXT_TEXT
 			SCHED_TEXT
 			LOCK_TEXT
-			KPROBES_TEXT
 			*(.gnu.warning)
 			*(.glue_7)
 			*(.glue_7t)
diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
index d24e5dd2aa7a..e88b77d01f0b 100644
--- a/arch/arm/kernel/vmlinux.lds.S
+++ b/arch/arm/kernel/vmlinux.lds.S
@@ -113,7 +113,6 @@ SECTIONS
 			SCHED_TEXT
 			LOCK_TEXT
 			HYPERVISOR_TEXT
-			KPROBES_TEXT
 			*(.gnu.warning)
 			*(.glue_7)
 			*(.glue_7t)
diff --git a/arch/avr32/kernel/entry-avr32b.S b/arch/avr32/kernel/entry-avr32b.S
index 7301f4806bbe..6a2cb50cb012 100644
--- a/arch/avr32/kernel/entry-avr32b.S
+++ b/arch/avr32/kernel/entry-avr32b.S
@@ -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,7 @@ fault_exit_work:
 	brcc	fault_resume_user
 	rjmp	enter_monitor_mode
 
-	.section .kprobes.text, "ax", @progbits
+	section_rng_asmtype(SECTION_TEXT, kprobes, ax, @progbits)
 	.type	handle_debug, @function
 handle_debug:
 	sub	sp, 4		/* r12_orig */
@@ -826,7 +827,7 @@ irq_level\level:
 	IRQ_LEVEL 2
 	IRQ_LEVEL 3
 
-	.section .kprobes.text, "ax", @progbits
+	section_rng_asmtype(SECTION_TEXT, kprobes, ax, @progbits)
 	.type	enter_monitor_mode, @function
 enter_monitor_mode:
 	/*
diff --git a/arch/avr32/kernel/vmlinux.lds.S b/arch/avr32/kernel/vmlinux.lds.S
index a4589176bed5..bf4f3f1f9dbb 100644
--- a/arch/avr32/kernel/vmlinux.lds.S
+++ b/arch/avr32/kernel/vmlinux.lds.S
@@ -49,7 +49,6 @@ SECTIONS
 		_stext = .;
 		*(.ex.text)
 		*(.irq.text)
-		KPROBES_TEXT
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
diff --git a/arch/blackfin/kernel/vmlinux.lds.S b/arch/blackfin/kernel/vmlinux.lds.S
index d920b959ff3a..8f7ca475c549 100644
--- a/arch/blackfin/kernel/vmlinux.lds.S
+++ b/arch/blackfin/kernel/vmlinux.lds.S
@@ -36,7 +36,6 @@ SECTIONS
 		LOCK_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
-		KPROBES_TEXT
 #ifdef CONFIG_ROMKERNEL
 		__sinittext = .;
 		INIT_TEXT
diff --git a/arch/c6x/kernel/vmlinux.lds.S b/arch/c6x/kernel/vmlinux.lds.S
index 50bc10f97bcb..e7aae42f632e 100644
--- a/arch/c6x/kernel/vmlinux.lds.S
+++ b/arch/c6x/kernel/vmlinux.lds.S
@@ -73,7 +73,6 @@ SECTIONS
 		LOCK_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
-		KPROBES_TEXT
 		*(.fixup)
 		*(.gnu.warning)
 	}
diff --git a/arch/hexagon/kernel/vmlinux.lds.S b/arch/hexagon/kernel/vmlinux.lds.S
index 5f268c1071b3..a358b699ec64 100644
--- a/arch/hexagon/kernel/vmlinux.lds.S
+++ b/arch/hexagon/kernel/vmlinux.lds.S
@@ -51,7 +51,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		*(.fixup)
 	}
 	_etext = .;
diff --git a/arch/ia64/kernel/jprobes.S b/arch/ia64/kernel/jprobes.S
index f69389c7be1d..552204c758ac 100644
--- a/arch/ia64/kernel/jprobes.S
+++ b/arch/ia64/kernel/jprobes.S
@@ -46,11 +46,12 @@
  */
 #include <asm/asmmacro.h>
 #include <asm/break.h>
+#include <asm/ranges.h>
 
 	/*
 	 * void jprobe_break(void)
 	 */
-	.section .kprobes.text, "ax"
+	section_rng(SECTION_TEXT, kprobes, ax)
 ENTRY(jprobe_break)
 	break.m __IA64_BREAK_JPROBE
 END(jprobe_break)
diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
index dc506b05ffbd..884f36d38989 100644
--- a/arch/ia64/kernel/vmlinux.lds.S
+++ b/arch/ia64/kernel/vmlinux.lds.S
@@ -47,7 +47,6 @@ SECTIONS {
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		*(.gnu.linkonce.t*)
 	}
 
diff --git a/arch/ia64/lib/flush.S b/arch/ia64/lib/flush.S
index 1d8c88860063..44b9d3416513 100644
--- a/arch/ia64/lib/flush.S
+++ b/arch/ia64/lib/flush.S
@@ -8,6 +8,7 @@
  */
 
 #include <asm/asmmacro.h>
+#include <asm/ranges.h>
 
 
 	/*
@@ -20,7 +21,7 @@
 	 *
 	 *	Note: "in0" and "in1" are preserved for debugging purposes.
 	 */
-	.section .kprobes.text,"ax"
+	section_rng(SECTION_TEXT, kprobes, ax)
 GLOBAL_ENTRY(flush_icache_range)
 
 	.prologue
@@ -72,7 +73,7 @@ END(flush_icache_range)
 	 *
 	 *	Note: "in0" and "in1" are preserved for debugging purposes.
 	 */
-	.section .kprobes.text,"ax"
+	section_rng(SECTION_TEXT, kprobes, ax)
 GLOBAL_ENTRY(clflush_cache_range)
 
 	.prologue
diff --git a/arch/metag/kernel/vmlinux.lds.S b/arch/metag/kernel/vmlinux.lds.S
index 150ace92c7ad..bee7031d6b65 100644
--- a/arch/metag/kernel/vmlinux.lds.S
+++ b/arch/metag/kernel/vmlinux.lds.S
@@ -22,7 +22,6 @@ SECTIONS
 	TEXT_TEXT
 	SCHED_TEXT
 	LOCK_TEXT
-	KPROBES_TEXT
 	IRQENTRY_TEXT
 	SOFTIRQENTRY_TEXT
 	*(.text.*)
diff --git a/arch/microblaze/kernel/vmlinux.lds.S b/arch/microblaze/kernel/vmlinux.lds.S
index 0a47f0410554..2da85501a97a 100644
--- a/arch/microblaze/kernel/vmlinux.lds.S
+++ b/arch/microblaze/kernel/vmlinux.lds.S
@@ -34,7 +34,6 @@ SECTIONS {
 		EXIT_CALL
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		. = ALIGN (4) ;
diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
index a82c178d0bb9..a4c1c9889bdf 100644
--- a/arch/mips/kernel/vmlinux.lds.S
+++ b/arch/mips/kernel/vmlinux.lds.S
@@ -56,7 +56,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		*(.text.*)
diff --git a/arch/mn10300/kernel/vmlinux.lds.S b/arch/mn10300/kernel/vmlinux.lds.S
index 13c4814c29f8..ead5efc01802 100644
--- a/arch/mn10300/kernel/vmlinux.lds.S
+++ b/arch/mn10300/kernel/vmlinux.lds.S
@@ -31,7 +31,6 @@ SECTIONS
 	TEXT_TEXT
 	SCHED_TEXT
 	LOCK_TEXT
-	KPROBES_TEXT
 	*(.fixup)
 	*(.gnu.warning)
 	} = 0xcb
diff --git a/arch/nios2/kernel/vmlinux.lds.S b/arch/nios2/kernel/vmlinux.lds.S
index e23e89539967..51647b5c45db 100644
--- a/arch/nios2/kernel/vmlinux.lds.S
+++ b/arch/nios2/kernel/vmlinux.lds.S
@@ -40,7 +40,6 @@ SECTIONS
 		LOCK_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
-		KPROBES_TEXT
 	} =0
 	_etext = .;
 
diff --git a/arch/openrisc/kernel/vmlinux.lds.S b/arch/openrisc/kernel/vmlinux.lds.S
index d936de4c07ca..1e09dd42d7fa 100644
--- a/arch/openrisc/kernel/vmlinux.lds.S
+++ b/arch/openrisc/kernel/vmlinux.lds.S
@@ -48,7 +48,6 @@ SECTIONS
 	  TEXT_TEXT
 	  SCHED_TEXT
 	  LOCK_TEXT
-	  KPROBES_TEXT
 	  IRQENTRY_TEXT
 	  SOFTIRQENTRY_TEXT
 	  *(.fixup)
diff --git a/arch/parisc/kernel/vmlinux.lds.S b/arch/parisc/kernel/vmlinux.lds.S
index f3ead0b6ce46..c48399848674 100644
--- a/arch/parisc/kernel/vmlinux.lds.S
+++ b/arch/parisc/kernel/vmlinux.lds.S
@@ -70,7 +70,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		*(.text.do_softirq)
diff --git a/arch/powerpc/include/asm/ppc_asm.h b/arch/powerpc/include/asm/ppc_asm.h
index d5d5b5e348f2..201c08d5895a 100644
--- a/arch/powerpc/include/asm/ppc_asm.h
+++ b/arch/powerpc/include/asm/ppc_asm.h
@@ -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"; \
+	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"; \
+	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";	\
+	section_rng(SECTION_TEXT, kprobes, a); \
 	.globl	n;	\
 n:
 
diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index b5fba689fca6..544856210081 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -53,7 +53,6 @@ SECTIONS
 		*(.text .fixup __ftr_alt_* .ref.text)
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 
diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S
index c51650a1ed16..db7938a841ae 100644
--- a/arch/s390/kernel/entry.S
+++ b/arch/s390/kernel/entry.S
@@ -23,6 +23,7 @@
 #include <asm/vx-insn.h>
 #include <asm/setup.h>
 #include <asm/nmi.h>
+#include <asm/ranges.h>
 
 __PT_R0      =	__PT_GPRS
 __PT_R1      =	__PT_GPRS + 8
@@ -162,7 +163,7 @@ _PIF_WORK	= (_PIF_PER_TRAP)
 		tm	off+\addr, \mask
 	.endm
 
-	.section .kprobes.text, "ax"
+	section_rng(SECTION_TEXT, kprobes, ax)
 .Ldummy:
 	/*
 	 * This nop exists only in order to avoid that __switch_to starts at
@@ -975,7 +976,7 @@ ENTRY(restart_int_handler)
 	brc	2,2b
 3:	j	3b
 
-	.section .kprobes.text, "ax"
+	section_rng(SECTION_TEXT, kprobes, ax)
 
 #ifdef CONFIG_CHECK_STACK
 /*
diff --git a/arch/s390/kernel/kprobes.c b/arch/s390/kernel/kprobes.c
index 250f5972536a..4c75c9cc64af 100644
--- a/arch/s390/kernel/kprobes.c
+++ b/arch/s390/kernel/kprobes.c
@@ -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);
diff --git a/arch/s390/kernel/mcount.S b/arch/s390/kernel/mcount.S
index e499370fbccb..813949240960 100644
--- a/arch/s390/kernel/mcount.S
+++ b/arch/s390/kernel/mcount.S
@@ -10,7 +10,7 @@
 #include <asm/ftrace.h>
 #include <asm/ptrace.h>
 
-	.section .kprobes.text, "ax"
+	section_rng(SECTION_TEXT, kprobes, ax,)
 
 ENTRY(ftrace_stub)
 	br	%r14
diff --git a/arch/s390/kernel/vmlinux.lds.S b/arch/s390/kernel/vmlinux.lds.S
index 429bfd111961..33b0baf2233c 100644
--- a/arch/s390/kernel/vmlinux.lds.S
+++ b/arch/s390/kernel/vmlinux.lds.S
@@ -36,7 +36,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		*(.fixup)
diff --git a/arch/score/kernel/vmlinux.lds.S b/arch/score/kernel/vmlinux.lds.S
index 7274b5c4287e..36ebcb3b1215 100644
--- a/arch/score/kernel/vmlinux.lds.S
+++ b/arch/score/kernel/vmlinux.lds.S
@@ -41,7 +41,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		*(.text.*)
 		*(.fixup)
 		. = ALIGN (4) ;
diff --git a/arch/sh/kernel/vmlinux.lds.S b/arch/sh/kernel/vmlinux.lds.S
index 235a4101999f..d8ae0a60cdf2 100644
--- a/arch/sh/kernel/vmlinux.lds.S
+++ b/arch/sh/kernel/vmlinux.lds.S
@@ -37,7 +37,6 @@ SECTIONS
 		EXTRA_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		*(.fixup)
diff --git a/arch/sparc/kernel/vmlinux.lds.S b/arch/sparc/kernel/vmlinux.lds.S
index d79b3b734245..017eb4d7ccca 100644
--- a/arch/sparc/kernel/vmlinux.lds.S
+++ b/arch/sparc/kernel/vmlinux.lds.S
@@ -50,7 +50,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		*(.gnu.warning)
diff --git a/arch/sparc/mm/ultra.S b/arch/sparc/mm/ultra.S
index b4f4733abc6e..6762b7db82c4 100644
--- a/arch/sparc/mm/ultra.S
+++ b/arch/sparc/mm/ultra.S
@@ -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"
+	section_rng(SECTION_TEXT, kprobes, ax)
 	.align		32
 	.globl		__flush_icache_page
 __flush_icache_page:	/* %o0 = phys_page */
diff --git a/arch/tile/kernel/vmlinux.lds.S b/arch/tile/kernel/vmlinux.lds.S
index 9d449caf8910..c222cea90b7a 100644
--- a/arch/tile/kernel/vmlinux.lds.S
+++ b/arch/tile/kernel/vmlinux.lds.S
@@ -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 */
diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
index 7847e5c0e0b5..5a08b2e7196d 100644
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -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)
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 9297a002d8e5..8a5dfa38fde3 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -98,7 +98,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		ENTRY_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index cd4313c3edf8..fa004a67ad53 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -324,7 +324,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
  */
@@ -335,7 +334,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[];
 
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 8048242b6a76..1664050e6560 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -444,12 +444,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) = .;			\
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index d7a0b579442c..a651a4fd537d 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -544,7 +544,7 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
 
 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
 #ifdef CONFIG_KPROBES
-# define __kprobes	__attribute__((__section__(".kprobes.text")))
+# define __kprobes	__LINUX_RANGE(SECTION_TEXT, kprobes)
 # define nokprobe_inline	__always_inline
 #else
 # define __kprobes
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index 8f6849084248..3f46b282a3f9 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -42,8 +42,11 @@
 #include <linux/ftrace.h>
 
 #ifdef CONFIG_KPROBES
+#include <linux/ranges.h>
 #include <asm/kprobes.h>
 
+DECLARE_SECTION_RANGE(kprobes);
+
 /* kprobe_status settings */
 #define KPROBE_HIT_ACTIVE	0x00000001
 #define KPROBE_HIT_SS		0x00000002
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index d10ab6b9b5e0..387605682622 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -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;
diff --git a/scripts/Makefile b/scripts/Makefile
index 1d80897a9644..77a0cc91628c 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -10,6 +10,7 @@
 # check-lc_ctype: Used in Documentation/DocBook
 
 HOST_EXTRACFLAGS += -I$(srctree)/tools/include
+HOST_EXTRACFLAGS += -U__KERNEL__
 
 hostprogs-$(CONFIG_KALLSYMS)     += kallsyms
 hostprogs-$(CONFIG_LOGO)         += pnmtologo
diff --git a/scripts/mod/Makefile b/scripts/mod/Makefile
index 8257ef422c0a..76905d4ac0d0 100644
--- a/scripts/mod/Makefile
+++ b/scripts/mod/Makefile
@@ -1,5 +1,7 @@
 OBJECT_FILES_NON_STANDARD := y
 
+HOST_EXTRACFLAGS += -U__KERNEL__
+
 hostprogs-y	:= modpost mk_elfconfig
 always		:= $(hostprogs-y) empty.o
 
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 48958d3cec9e..12ddced5df84 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -19,10 +19,16 @@
 #include <stdbool.h>
 #include <errno.h>
 #include "modpost.h"
+
 #include "../../include/generated/autoconf.h"
 #include "../../include/linux/license.h"
 #include "../../include/linux/export.h"
 
+#include "../../include/linux/sections.h"
+#include "../../include/asm-generic/sections.h"
+#include "../../include/linux/ranges.h"
+#include "../../include/asm-generic/ranges.h"
+
 /* Are we using CONFIG_MODVERSIONS? */
 static int modversions = 0;
 /* Warn about undefined symbols? (do so if we have vmlinux) */
@@ -888,7 +894,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"
+		SECTION_RNG(SECTION_TEXT, kprobes)
 #define OTHER_TEXT_SECTIONS ".ref.text", ".head.text", ".spinlock.text", \
 		".fixup", ".entry.text", ".exception.text", ".text.*", \
 		".coldtext"
diff --git a/scripts/recordmcount.c b/scripts/recordmcount.c
index e167592793a7..8381d75235d4 100644
--- a/scripts/recordmcount.c
+++ b/scripts/recordmcount.c
@@ -33,6 +33,11 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "../../include/linux/sections.h"
+#include "../../include/asm-generic/sections.h"
+#include "../../include/linux/ranges.h"
+#include "../../include/asm-generic/ranges.h"
+
 #ifndef EM_METAG
 /* Remove this when these make it to the standard system elf.h. */
 #define EM_METAG      174
@@ -356,7 +361,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(SECTION_RNG(SECTION_TEXT, kprobe), txtname) = 0 ||
 		strcmp(".text.unlikely", txtname) = 0;
 }
 
diff --git a/scripts/recordmcount.pl b/scripts/recordmcount.pl
index 96e2486a6fc4..f663a7c5d6ab 100755
--- a/scripts/recordmcount.pl
+++ b/scripts/recordmcount.pl
@@ -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,
 );
 
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 12/13] kprobes: port .kprobes.text to section range
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 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/avr32/kernel/entry-avr32b.S     |  5 +++--
 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                |  5 +++--
 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            |  2 +-
 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/sections.h       |  2 --
 include/asm-generic/vmlinux.lds.h    |  6 ------
 include/linux/compiler.h             |  2 +-
 include/linux/kprobes.h              |  3 +++
 kernel/kprobes.c                     |  6 ++++--
 scripts/Makefile                     |  1 +
 scripts/mod/Makefile                 |  2 ++
 scripts/mod/modpost.c                |  8 +++++++-
 scripts/recordmcount.c               |  7 ++++++-
 scripts/recordmcount.pl              |  2 +-
 42 files changed, 53 insertions(+), 58 deletions(-)

diff --git a/arch/arc/kernel/vmlinux.lds.S b/arch/arc/kernel/vmlinux.lds.S
index 894e696bddaa..52f23df2b9b6 100644
--- a/arch/arc/kernel/vmlinux.lds.S
+++ b/arch/arc/kernel/vmlinux.lds.S
@@ -98,7 +98,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		*(.fixup)
 		*(.gnu.warning)
 	}
diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
index bc5f50799d75..e56ba05eae34 100644
--- a/arch/arm/kernel/entry-armv.S
+++ b/arch/arm/kernel/entry-armv.S
@@ -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
+	section_rng_asmtype(SECTION_TEXT, kprobes, ax, %progbits)
 #else
 	.text
 #endif
diff --git a/arch/arm/kernel/vmlinux-xip.lds.S b/arch/arm/kernel/vmlinux-xip.lds.S
index cba1ec899a69..3aea8834e3d2 100644
--- a/arch/arm/kernel/vmlinux-xip.lds.S
+++ b/arch/arm/kernel/vmlinux-xip.lds.S
@@ -99,7 +99,6 @@ SECTIONS
 			TEXT_TEXT
 			SCHED_TEXT
 			LOCK_TEXT
-			KPROBES_TEXT
 			*(.gnu.warning)
 			*(.glue_7)
 			*(.glue_7t)
diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
index d24e5dd2aa7a..e88b77d01f0b 100644
--- a/arch/arm/kernel/vmlinux.lds.S
+++ b/arch/arm/kernel/vmlinux.lds.S
@@ -113,7 +113,6 @@ SECTIONS
 			SCHED_TEXT
 			LOCK_TEXT
 			HYPERVISOR_TEXT
-			KPROBES_TEXT
 			*(.gnu.warning)
 			*(.glue_7)
 			*(.glue_7t)
diff --git a/arch/avr32/kernel/entry-avr32b.S b/arch/avr32/kernel/entry-avr32b.S
index 7301f4806bbe..6a2cb50cb012 100644
--- a/arch/avr32/kernel/entry-avr32b.S
+++ b/arch/avr32/kernel/entry-avr32b.S
@@ -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,7 @@ fault_exit_work:
 	brcc	fault_resume_user
 	rjmp	enter_monitor_mode
 
-	.section .kprobes.text, "ax", @progbits
+	section_rng_asmtype(SECTION_TEXT, kprobes, ax, @progbits)
 	.type	handle_debug, @function
 handle_debug:
 	sub	sp, 4		/* r12_orig */
@@ -826,7 +827,7 @@ irq_level\level:
 	IRQ_LEVEL 2
 	IRQ_LEVEL 3
 
-	.section .kprobes.text, "ax", @progbits
+	section_rng_asmtype(SECTION_TEXT, kprobes, ax, @progbits)
 	.type	enter_monitor_mode, @function
 enter_monitor_mode:
 	/*
diff --git a/arch/avr32/kernel/vmlinux.lds.S b/arch/avr32/kernel/vmlinux.lds.S
index a4589176bed5..bf4f3f1f9dbb 100644
--- a/arch/avr32/kernel/vmlinux.lds.S
+++ b/arch/avr32/kernel/vmlinux.lds.S
@@ -49,7 +49,6 @@ SECTIONS
 		_stext = .;
 		*(.ex.text)
 		*(.irq.text)
-		KPROBES_TEXT
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
diff --git a/arch/blackfin/kernel/vmlinux.lds.S b/arch/blackfin/kernel/vmlinux.lds.S
index d920b959ff3a..8f7ca475c549 100644
--- a/arch/blackfin/kernel/vmlinux.lds.S
+++ b/arch/blackfin/kernel/vmlinux.lds.S
@@ -36,7 +36,6 @@ SECTIONS
 		LOCK_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
-		KPROBES_TEXT
 #ifdef CONFIG_ROMKERNEL
 		__sinittext = .;
 		INIT_TEXT
diff --git a/arch/c6x/kernel/vmlinux.lds.S b/arch/c6x/kernel/vmlinux.lds.S
index 50bc10f97bcb..e7aae42f632e 100644
--- a/arch/c6x/kernel/vmlinux.lds.S
+++ b/arch/c6x/kernel/vmlinux.lds.S
@@ -73,7 +73,6 @@ SECTIONS
 		LOCK_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
-		KPROBES_TEXT
 		*(.fixup)
 		*(.gnu.warning)
 	}
diff --git a/arch/hexagon/kernel/vmlinux.lds.S b/arch/hexagon/kernel/vmlinux.lds.S
index 5f268c1071b3..a358b699ec64 100644
--- a/arch/hexagon/kernel/vmlinux.lds.S
+++ b/arch/hexagon/kernel/vmlinux.lds.S
@@ -51,7 +51,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		*(.fixup)
 	}
 	_etext = .;
diff --git a/arch/ia64/kernel/jprobes.S b/arch/ia64/kernel/jprobes.S
index f69389c7be1d..552204c758ac 100644
--- a/arch/ia64/kernel/jprobes.S
+++ b/arch/ia64/kernel/jprobes.S
@@ -46,11 +46,12 @@
  */
 #include <asm/asmmacro.h>
 #include <asm/break.h>
+#include <asm/ranges.h>
 
 	/*
 	 * void jprobe_break(void)
 	 */
-	.section .kprobes.text, "ax"
+	section_rng(SECTION_TEXT, kprobes, ax)
 ENTRY(jprobe_break)
 	break.m __IA64_BREAK_JPROBE
 END(jprobe_break)
diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
index dc506b05ffbd..884f36d38989 100644
--- a/arch/ia64/kernel/vmlinux.lds.S
+++ b/arch/ia64/kernel/vmlinux.lds.S
@@ -47,7 +47,6 @@ SECTIONS {
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		*(.gnu.linkonce.t*)
 	}
 
diff --git a/arch/ia64/lib/flush.S b/arch/ia64/lib/flush.S
index 1d8c88860063..44b9d3416513 100644
--- a/arch/ia64/lib/flush.S
+++ b/arch/ia64/lib/flush.S
@@ -8,6 +8,7 @@
  */
 
 #include <asm/asmmacro.h>
+#include <asm/ranges.h>
 
 
 	/*
@@ -20,7 +21,7 @@
 	 *
 	 *	Note: "in0" and "in1" are preserved for debugging purposes.
 	 */
-	.section .kprobes.text,"ax"
+	section_rng(SECTION_TEXT, kprobes, ax)
 GLOBAL_ENTRY(flush_icache_range)
 
 	.prologue
@@ -72,7 +73,7 @@ END(flush_icache_range)
 	 *
 	 *	Note: "in0" and "in1" are preserved for debugging purposes.
 	 */
-	.section .kprobes.text,"ax"
+	section_rng(SECTION_TEXT, kprobes, ax)
 GLOBAL_ENTRY(clflush_cache_range)
 
 	.prologue
diff --git a/arch/metag/kernel/vmlinux.lds.S b/arch/metag/kernel/vmlinux.lds.S
index 150ace92c7ad..bee7031d6b65 100644
--- a/arch/metag/kernel/vmlinux.lds.S
+++ b/arch/metag/kernel/vmlinux.lds.S
@@ -22,7 +22,6 @@ SECTIONS
 	TEXT_TEXT
 	SCHED_TEXT
 	LOCK_TEXT
-	KPROBES_TEXT
 	IRQENTRY_TEXT
 	SOFTIRQENTRY_TEXT
 	*(.text.*)
diff --git a/arch/microblaze/kernel/vmlinux.lds.S b/arch/microblaze/kernel/vmlinux.lds.S
index 0a47f0410554..2da85501a97a 100644
--- a/arch/microblaze/kernel/vmlinux.lds.S
+++ b/arch/microblaze/kernel/vmlinux.lds.S
@@ -34,7 +34,6 @@ SECTIONS {
 		EXIT_CALL
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		. = ALIGN (4) ;
diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
index a82c178d0bb9..a4c1c9889bdf 100644
--- a/arch/mips/kernel/vmlinux.lds.S
+++ b/arch/mips/kernel/vmlinux.lds.S
@@ -56,7 +56,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		*(.text.*)
diff --git a/arch/mn10300/kernel/vmlinux.lds.S b/arch/mn10300/kernel/vmlinux.lds.S
index 13c4814c29f8..ead5efc01802 100644
--- a/arch/mn10300/kernel/vmlinux.lds.S
+++ b/arch/mn10300/kernel/vmlinux.lds.S
@@ -31,7 +31,6 @@ SECTIONS
 	TEXT_TEXT
 	SCHED_TEXT
 	LOCK_TEXT
-	KPROBES_TEXT
 	*(.fixup)
 	*(.gnu.warning)
 	} = 0xcb
diff --git a/arch/nios2/kernel/vmlinux.lds.S b/arch/nios2/kernel/vmlinux.lds.S
index e23e89539967..51647b5c45db 100644
--- a/arch/nios2/kernel/vmlinux.lds.S
+++ b/arch/nios2/kernel/vmlinux.lds.S
@@ -40,7 +40,6 @@ SECTIONS
 		LOCK_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
-		KPROBES_TEXT
 	} =0
 	_etext = .;
 
diff --git a/arch/openrisc/kernel/vmlinux.lds.S b/arch/openrisc/kernel/vmlinux.lds.S
index d936de4c07ca..1e09dd42d7fa 100644
--- a/arch/openrisc/kernel/vmlinux.lds.S
+++ b/arch/openrisc/kernel/vmlinux.lds.S
@@ -48,7 +48,6 @@ SECTIONS
 	  TEXT_TEXT
 	  SCHED_TEXT
 	  LOCK_TEXT
-	  KPROBES_TEXT
 	  IRQENTRY_TEXT
 	  SOFTIRQENTRY_TEXT
 	  *(.fixup)
diff --git a/arch/parisc/kernel/vmlinux.lds.S b/arch/parisc/kernel/vmlinux.lds.S
index f3ead0b6ce46..c48399848674 100644
--- a/arch/parisc/kernel/vmlinux.lds.S
+++ b/arch/parisc/kernel/vmlinux.lds.S
@@ -70,7 +70,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		*(.text.do_softirq)
diff --git a/arch/powerpc/include/asm/ppc_asm.h b/arch/powerpc/include/asm/ppc_asm.h
index d5d5b5e348f2..201c08d5895a 100644
--- a/arch/powerpc/include/asm/ppc_asm.h
+++ b/arch/powerpc/include/asm/ppc_asm.h
@@ -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"; \
+	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"; \
+	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";	\
+	section_rng(SECTION_TEXT, kprobes, a); \
 	.globl	n;	\
 n:
 
diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index b5fba689fca6..544856210081 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -53,7 +53,6 @@ SECTIONS
 		*(.text .fixup __ftr_alt_* .ref.text)
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 
diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S
index c51650a1ed16..db7938a841ae 100644
--- a/arch/s390/kernel/entry.S
+++ b/arch/s390/kernel/entry.S
@@ -23,6 +23,7 @@
 #include <asm/vx-insn.h>
 #include <asm/setup.h>
 #include <asm/nmi.h>
+#include <asm/ranges.h>
 
 __PT_R0      =	__PT_GPRS
 __PT_R1      =	__PT_GPRS + 8
@@ -162,7 +163,7 @@ _PIF_WORK	= (_PIF_PER_TRAP)
 		tm	off+\addr, \mask
 	.endm
 
-	.section .kprobes.text, "ax"
+	section_rng(SECTION_TEXT, kprobes, ax)
 .Ldummy:
 	/*
 	 * This nop exists only in order to avoid that __switch_to starts at
@@ -975,7 +976,7 @@ ENTRY(restart_int_handler)
 	brc	2,2b
 3:	j	3b
 
-	.section .kprobes.text, "ax"
+	section_rng(SECTION_TEXT, kprobes, ax)
 
 #ifdef CONFIG_CHECK_STACK
 /*
diff --git a/arch/s390/kernel/kprobes.c b/arch/s390/kernel/kprobes.c
index 250f5972536a..4c75c9cc64af 100644
--- a/arch/s390/kernel/kprobes.c
+++ b/arch/s390/kernel/kprobes.c
@@ -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);
diff --git a/arch/s390/kernel/mcount.S b/arch/s390/kernel/mcount.S
index e499370fbccb..813949240960 100644
--- a/arch/s390/kernel/mcount.S
+++ b/arch/s390/kernel/mcount.S
@@ -10,7 +10,7 @@
 #include <asm/ftrace.h>
 #include <asm/ptrace.h>
 
-	.section .kprobes.text, "ax"
+	section_rng(SECTION_TEXT, kprobes, ax,)
 
 ENTRY(ftrace_stub)
 	br	%r14
diff --git a/arch/s390/kernel/vmlinux.lds.S b/arch/s390/kernel/vmlinux.lds.S
index 429bfd111961..33b0baf2233c 100644
--- a/arch/s390/kernel/vmlinux.lds.S
+++ b/arch/s390/kernel/vmlinux.lds.S
@@ -36,7 +36,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		*(.fixup)
diff --git a/arch/score/kernel/vmlinux.lds.S b/arch/score/kernel/vmlinux.lds.S
index 7274b5c4287e..36ebcb3b1215 100644
--- a/arch/score/kernel/vmlinux.lds.S
+++ b/arch/score/kernel/vmlinux.lds.S
@@ -41,7 +41,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		*(.text.*)
 		*(.fixup)
 		. = ALIGN (4) ;
diff --git a/arch/sh/kernel/vmlinux.lds.S b/arch/sh/kernel/vmlinux.lds.S
index 235a4101999f..d8ae0a60cdf2 100644
--- a/arch/sh/kernel/vmlinux.lds.S
+++ b/arch/sh/kernel/vmlinux.lds.S
@@ -37,7 +37,6 @@ SECTIONS
 		EXTRA_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		*(.fixup)
diff --git a/arch/sparc/kernel/vmlinux.lds.S b/arch/sparc/kernel/vmlinux.lds.S
index d79b3b734245..017eb4d7ccca 100644
--- a/arch/sparc/kernel/vmlinux.lds.S
+++ b/arch/sparc/kernel/vmlinux.lds.S
@@ -50,7 +50,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		*(.gnu.warning)
diff --git a/arch/sparc/mm/ultra.S b/arch/sparc/mm/ultra.S
index b4f4733abc6e..6762b7db82c4 100644
--- a/arch/sparc/mm/ultra.S
+++ b/arch/sparc/mm/ultra.S
@@ -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"
+	section_rng(SECTION_TEXT, kprobes, ax)
 	.align		32
 	.globl		__flush_icache_page
 __flush_icache_page:	/* %o0 = phys_page */
diff --git a/arch/tile/kernel/vmlinux.lds.S b/arch/tile/kernel/vmlinux.lds.S
index 9d449caf8910..c222cea90b7a 100644
--- a/arch/tile/kernel/vmlinux.lds.S
+++ b/arch/tile/kernel/vmlinux.lds.S
@@ -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 */
diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
index 7847e5c0e0b5..5a08b2e7196d 100644
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -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)
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 9297a002d8e5..8a5dfa38fde3 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -98,7 +98,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		ENTRY_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index cd4313c3edf8..fa004a67ad53 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -324,7 +324,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
  */
@@ -335,7 +334,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[];
 
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 8048242b6a76..1664050e6560 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -444,12 +444,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) = .;			\
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index d7a0b579442c..a651a4fd537d 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -544,7 +544,7 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
 
 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
 #ifdef CONFIG_KPROBES
-# define __kprobes	__attribute__((__section__(".kprobes.text")))
+# define __kprobes	__LINUX_RANGE(SECTION_TEXT, kprobes)
 # define nokprobe_inline	__always_inline
 #else
 # define __kprobes
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index 8f6849084248..3f46b282a3f9 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -42,8 +42,11 @@
 #include <linux/ftrace.h>
 
 #ifdef CONFIG_KPROBES
+#include <linux/ranges.h>
 #include <asm/kprobes.h>
 
+DECLARE_SECTION_RANGE(kprobes);
+
 /* kprobe_status settings */
 #define KPROBE_HIT_ACTIVE	0x00000001
 #define KPROBE_HIT_SS		0x00000002
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index d10ab6b9b5e0..387605682622 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -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;
diff --git a/scripts/Makefile b/scripts/Makefile
index 1d80897a9644..77a0cc91628c 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -10,6 +10,7 @@
 # check-lc_ctype: Used in Documentation/DocBook
 
 HOST_EXTRACFLAGS += -I$(srctree)/tools/include
+HOST_EXTRACFLAGS += -U__KERNEL__
 
 hostprogs-$(CONFIG_KALLSYMS)     += kallsyms
 hostprogs-$(CONFIG_LOGO)         += pnmtologo
diff --git a/scripts/mod/Makefile b/scripts/mod/Makefile
index 8257ef422c0a..76905d4ac0d0 100644
--- a/scripts/mod/Makefile
+++ b/scripts/mod/Makefile
@@ -1,5 +1,7 @@
 OBJECT_FILES_NON_STANDARD := y
 
+HOST_EXTRACFLAGS += -U__KERNEL__
+
 hostprogs-y	:= modpost mk_elfconfig
 always		:= $(hostprogs-y) empty.o
 
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 48958d3cec9e..12ddced5df84 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -19,10 +19,16 @@
 #include <stdbool.h>
 #include <errno.h>
 #include "modpost.h"
+
 #include "../../include/generated/autoconf.h"
 #include "../../include/linux/license.h"
 #include "../../include/linux/export.h"
 
+#include "../../include/linux/sections.h"
+#include "../../include/asm-generic/sections.h"
+#include "../../include/linux/ranges.h"
+#include "../../include/asm-generic/ranges.h"
+
 /* Are we using CONFIG_MODVERSIONS? */
 static int modversions = 0;
 /* Warn about undefined symbols? (do so if we have vmlinux) */
@@ -888,7 +894,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"
+		SECTION_RNG(SECTION_TEXT, kprobes)
 #define OTHER_TEXT_SECTIONS ".ref.text", ".head.text", ".spinlock.text", \
 		".fixup", ".entry.text", ".exception.text", ".text.*", \
 		".coldtext"
diff --git a/scripts/recordmcount.c b/scripts/recordmcount.c
index e167592793a7..8381d75235d4 100644
--- a/scripts/recordmcount.c
+++ b/scripts/recordmcount.c
@@ -33,6 +33,11 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "../../include/linux/sections.h"
+#include "../../include/asm-generic/sections.h"
+#include "../../include/linux/ranges.h"
+#include "../../include/asm-generic/ranges.h"
+
 #ifndef EM_METAG
 /* Remove this when these make it to the standard system elf.h. */
 #define EM_METAG      174
@@ -356,7 +361,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(SECTION_RNG(SECTION_TEXT, kprobe), txtname) == 0 ||
 		strcmp(".text.unlikely", txtname) == 0;
 }
 
diff --git a/scripts/recordmcount.pl b/scripts/recordmcount.pl
index 96e2486a6fc4..f663a7c5d6ab 100755
--- a/scripts/recordmcount.pl
+++ b/scripts/recordmcount.pl
@@ -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,
 );
 
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 12/13] kprobes: port .kprobes.text to section range
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe, Luis R. Rodriguez

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

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 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/avr32/kernel/entry-avr32b.S     |  5 +++--
 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                |  5 +++--
 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            |  2 +-
 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/sections.h       |  2 --
 include/asm-generic/vmlinux.lds.h    |  6 ------
 include/linux/compiler.h             |  2 +-
 include/linux/kprobes.h              |  3 +++
 kernel/kprobes.c                     |  6 ++++--
 scripts/Makefile                     |  1 +
 scripts/mod/Makefile                 |  2 ++
 scripts/mod/modpost.c                |  8 +++++++-
 scripts/recordmcount.c               |  7 ++++++-
 scripts/recordmcount.pl              |  2 +-
 42 files changed, 53 insertions(+), 58 deletions(-)

diff --git a/arch/arc/kernel/vmlinux.lds.S b/arch/arc/kernel/vmlinux.lds.S
index 894e696bddaa..52f23df2b9b6 100644
--- a/arch/arc/kernel/vmlinux.lds.S
+++ b/arch/arc/kernel/vmlinux.lds.S
@@ -98,7 +98,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		*(.fixup)
 		*(.gnu.warning)
 	}
diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
index bc5f50799d75..e56ba05eae34 100644
--- a/arch/arm/kernel/entry-armv.S
+++ b/arch/arm/kernel/entry-armv.S
@@ -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
+	section_rng_asmtype(SECTION_TEXT, kprobes, ax, %progbits)
 #else
 	.text
 #endif
diff --git a/arch/arm/kernel/vmlinux-xip.lds.S b/arch/arm/kernel/vmlinux-xip.lds.S
index cba1ec899a69..3aea8834e3d2 100644
--- a/arch/arm/kernel/vmlinux-xip.lds.S
+++ b/arch/arm/kernel/vmlinux-xip.lds.S
@@ -99,7 +99,6 @@ SECTIONS
 			TEXT_TEXT
 			SCHED_TEXT
 			LOCK_TEXT
-			KPROBES_TEXT
 			*(.gnu.warning)
 			*(.glue_7)
 			*(.glue_7t)
diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
index d24e5dd2aa7a..e88b77d01f0b 100644
--- a/arch/arm/kernel/vmlinux.lds.S
+++ b/arch/arm/kernel/vmlinux.lds.S
@@ -113,7 +113,6 @@ SECTIONS
 			SCHED_TEXT
 			LOCK_TEXT
 			HYPERVISOR_TEXT
-			KPROBES_TEXT
 			*(.gnu.warning)
 			*(.glue_7)
 			*(.glue_7t)
diff --git a/arch/avr32/kernel/entry-avr32b.S b/arch/avr32/kernel/entry-avr32b.S
index 7301f4806bbe..6a2cb50cb012 100644
--- a/arch/avr32/kernel/entry-avr32b.S
+++ b/arch/avr32/kernel/entry-avr32b.S
@@ -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,7 @@ fault_exit_work:
 	brcc	fault_resume_user
 	rjmp	enter_monitor_mode
 
-	.section .kprobes.text, "ax", @progbits
+	section_rng_asmtype(SECTION_TEXT, kprobes, ax, @progbits)
 	.type	handle_debug, @function
 handle_debug:
 	sub	sp, 4		/* r12_orig */
@@ -826,7 +827,7 @@ irq_level\level:
 	IRQ_LEVEL 2
 	IRQ_LEVEL 3
 
-	.section .kprobes.text, "ax", @progbits
+	section_rng_asmtype(SECTION_TEXT, kprobes, ax, @progbits)
 	.type	enter_monitor_mode, @function
 enter_monitor_mode:
 	/*
diff --git a/arch/avr32/kernel/vmlinux.lds.S b/arch/avr32/kernel/vmlinux.lds.S
index a4589176bed5..bf4f3f1f9dbb 100644
--- a/arch/avr32/kernel/vmlinux.lds.S
+++ b/arch/avr32/kernel/vmlinux.lds.S
@@ -49,7 +49,6 @@ SECTIONS
 		_stext = .;
 		*(.ex.text)
 		*(.irq.text)
-		KPROBES_TEXT
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
diff --git a/arch/blackfin/kernel/vmlinux.lds.S b/arch/blackfin/kernel/vmlinux.lds.S
index d920b959ff3a..8f7ca475c549 100644
--- a/arch/blackfin/kernel/vmlinux.lds.S
+++ b/arch/blackfin/kernel/vmlinux.lds.S
@@ -36,7 +36,6 @@ SECTIONS
 		LOCK_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
-		KPROBES_TEXT
 #ifdef CONFIG_ROMKERNEL
 		__sinittext = .;
 		INIT_TEXT
diff --git a/arch/c6x/kernel/vmlinux.lds.S b/arch/c6x/kernel/vmlinux.lds.S
index 50bc10f97bcb..e7aae42f632e 100644
--- a/arch/c6x/kernel/vmlinux.lds.S
+++ b/arch/c6x/kernel/vmlinux.lds.S
@@ -73,7 +73,6 @@ SECTIONS
 		LOCK_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
-		KPROBES_TEXT
 		*(.fixup)
 		*(.gnu.warning)
 	}
diff --git a/arch/hexagon/kernel/vmlinux.lds.S b/arch/hexagon/kernel/vmlinux.lds.S
index 5f268c1071b3..a358b699ec64 100644
--- a/arch/hexagon/kernel/vmlinux.lds.S
+++ b/arch/hexagon/kernel/vmlinux.lds.S
@@ -51,7 +51,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		*(.fixup)
 	}
 	_etext = .;
diff --git a/arch/ia64/kernel/jprobes.S b/arch/ia64/kernel/jprobes.S
index f69389c7be1d..552204c758ac 100644
--- a/arch/ia64/kernel/jprobes.S
+++ b/arch/ia64/kernel/jprobes.S
@@ -46,11 +46,12 @@
  */
 #include <asm/asmmacro.h>
 #include <asm/break.h>
+#include <asm/ranges.h>
 
 	/*
 	 * void jprobe_break(void)
 	 */
-	.section .kprobes.text, "ax"
+	section_rng(SECTION_TEXT, kprobes, ax)
 ENTRY(jprobe_break)
 	break.m __IA64_BREAK_JPROBE
 END(jprobe_break)
diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
index dc506b05ffbd..884f36d38989 100644
--- a/arch/ia64/kernel/vmlinux.lds.S
+++ b/arch/ia64/kernel/vmlinux.lds.S
@@ -47,7 +47,6 @@ SECTIONS {
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		*(.gnu.linkonce.t*)
 	}
 
diff --git a/arch/ia64/lib/flush.S b/arch/ia64/lib/flush.S
index 1d8c88860063..44b9d3416513 100644
--- a/arch/ia64/lib/flush.S
+++ b/arch/ia64/lib/flush.S
@@ -8,6 +8,7 @@
  */
 
 #include <asm/asmmacro.h>
+#include <asm/ranges.h>
 
 
 	/*
@@ -20,7 +21,7 @@
 	 *
 	 *	Note: "in0" and "in1" are preserved for debugging purposes.
 	 */
-	.section .kprobes.text,"ax"
+	section_rng(SECTION_TEXT, kprobes, ax)
 GLOBAL_ENTRY(flush_icache_range)
 
 	.prologue
@@ -72,7 +73,7 @@ END(flush_icache_range)
 	 *
 	 *	Note: "in0" and "in1" are preserved for debugging purposes.
 	 */
-	.section .kprobes.text,"ax"
+	section_rng(SECTION_TEXT, kprobes, ax)
 GLOBAL_ENTRY(clflush_cache_range)
 
 	.prologue
diff --git a/arch/metag/kernel/vmlinux.lds.S b/arch/metag/kernel/vmlinux.lds.S
index 150ace92c7ad..bee7031d6b65 100644
--- a/arch/metag/kernel/vmlinux.lds.S
+++ b/arch/metag/kernel/vmlinux.lds.S
@@ -22,7 +22,6 @@ SECTIONS
 	TEXT_TEXT
 	SCHED_TEXT
 	LOCK_TEXT
-	KPROBES_TEXT
 	IRQENTRY_TEXT
 	SOFTIRQENTRY_TEXT
 	*(.text.*)
diff --git a/arch/microblaze/kernel/vmlinux.lds.S b/arch/microblaze/kernel/vmlinux.lds.S
index 0a47f0410554..2da85501a97a 100644
--- a/arch/microblaze/kernel/vmlinux.lds.S
+++ b/arch/microblaze/kernel/vmlinux.lds.S
@@ -34,7 +34,6 @@ SECTIONS {
 		EXIT_CALL
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		. = ALIGN (4) ;
diff --git a/arch/mips/kernel/vmlinux.lds.S b/arch/mips/kernel/vmlinux.lds.S
index a82c178d0bb9..a4c1c9889bdf 100644
--- a/arch/mips/kernel/vmlinux.lds.S
+++ b/arch/mips/kernel/vmlinux.lds.S
@@ -56,7 +56,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		*(.text.*)
diff --git a/arch/mn10300/kernel/vmlinux.lds.S b/arch/mn10300/kernel/vmlinux.lds.S
index 13c4814c29f8..ead5efc01802 100644
--- a/arch/mn10300/kernel/vmlinux.lds.S
+++ b/arch/mn10300/kernel/vmlinux.lds.S
@@ -31,7 +31,6 @@ SECTIONS
 	TEXT_TEXT
 	SCHED_TEXT
 	LOCK_TEXT
-	KPROBES_TEXT
 	*(.fixup)
 	*(.gnu.warning)
 	} = 0xcb
diff --git a/arch/nios2/kernel/vmlinux.lds.S b/arch/nios2/kernel/vmlinux.lds.S
index e23e89539967..51647b5c45db 100644
--- a/arch/nios2/kernel/vmlinux.lds.S
+++ b/arch/nios2/kernel/vmlinux.lds.S
@@ -40,7 +40,6 @@ SECTIONS
 		LOCK_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
-		KPROBES_TEXT
 	} =0
 	_etext = .;
 
diff --git a/arch/openrisc/kernel/vmlinux.lds.S b/arch/openrisc/kernel/vmlinux.lds.S
index d936de4c07ca..1e09dd42d7fa 100644
--- a/arch/openrisc/kernel/vmlinux.lds.S
+++ b/arch/openrisc/kernel/vmlinux.lds.S
@@ -48,7 +48,6 @@ SECTIONS
 	  TEXT_TEXT
 	  SCHED_TEXT
 	  LOCK_TEXT
-	  KPROBES_TEXT
 	  IRQENTRY_TEXT
 	  SOFTIRQENTRY_TEXT
 	  *(.fixup)
diff --git a/arch/parisc/kernel/vmlinux.lds.S b/arch/parisc/kernel/vmlinux.lds.S
index f3ead0b6ce46..c48399848674 100644
--- a/arch/parisc/kernel/vmlinux.lds.S
+++ b/arch/parisc/kernel/vmlinux.lds.S
@@ -70,7 +70,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		*(.text.do_softirq)
diff --git a/arch/powerpc/include/asm/ppc_asm.h b/arch/powerpc/include/asm/ppc_asm.h
index d5d5b5e348f2..201c08d5895a 100644
--- a/arch/powerpc/include/asm/ppc_asm.h
+++ b/arch/powerpc/include/asm/ppc_asm.h
@@ -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"; \
+	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"; \
+	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";	\
+	section_rng(SECTION_TEXT, kprobes, a); \
 	.globl	n;	\
 n:
 
diff --git a/arch/powerpc/kernel/vmlinux.lds.S b/arch/powerpc/kernel/vmlinux.lds.S
index b5fba689fca6..544856210081 100644
--- a/arch/powerpc/kernel/vmlinux.lds.S
+++ b/arch/powerpc/kernel/vmlinux.lds.S
@@ -53,7 +53,6 @@ SECTIONS
 		*(.text .fixup __ftr_alt_* .ref.text)
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 
diff --git a/arch/s390/kernel/entry.S b/arch/s390/kernel/entry.S
index c51650a1ed16..db7938a841ae 100644
--- a/arch/s390/kernel/entry.S
+++ b/arch/s390/kernel/entry.S
@@ -23,6 +23,7 @@
 #include <asm/vx-insn.h>
 #include <asm/setup.h>
 #include <asm/nmi.h>
+#include <asm/ranges.h>
 
 __PT_R0      =	__PT_GPRS
 __PT_R1      =	__PT_GPRS + 8
@@ -162,7 +163,7 @@ _PIF_WORK	= (_PIF_PER_TRAP)
 		tm	off+\addr, \mask
 	.endm
 
-	.section .kprobes.text, "ax"
+	section_rng(SECTION_TEXT, kprobes, ax)
 .Ldummy:
 	/*
 	 * This nop exists only in order to avoid that __switch_to starts at
@@ -975,7 +976,7 @@ ENTRY(restart_int_handler)
 	brc	2,2b
 3:	j	3b
 
-	.section .kprobes.text, "ax"
+	section_rng(SECTION_TEXT, kprobes, ax)
 
 #ifdef CONFIG_CHECK_STACK
 /*
diff --git a/arch/s390/kernel/kprobes.c b/arch/s390/kernel/kprobes.c
index 250f5972536a..4c75c9cc64af 100644
--- a/arch/s390/kernel/kprobes.c
+++ b/arch/s390/kernel/kprobes.c
@@ -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);
diff --git a/arch/s390/kernel/mcount.S b/arch/s390/kernel/mcount.S
index e499370fbccb..813949240960 100644
--- a/arch/s390/kernel/mcount.S
+++ b/arch/s390/kernel/mcount.S
@@ -10,7 +10,7 @@
 #include <asm/ftrace.h>
 #include <asm/ptrace.h>
 
-	.section .kprobes.text, "ax"
+	section_rng(SECTION_TEXT, kprobes, ax,)
 
 ENTRY(ftrace_stub)
 	br	%r14
diff --git a/arch/s390/kernel/vmlinux.lds.S b/arch/s390/kernel/vmlinux.lds.S
index 429bfd111961..33b0baf2233c 100644
--- a/arch/s390/kernel/vmlinux.lds.S
+++ b/arch/s390/kernel/vmlinux.lds.S
@@ -36,7 +36,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		*(.fixup)
diff --git a/arch/score/kernel/vmlinux.lds.S b/arch/score/kernel/vmlinux.lds.S
index 7274b5c4287e..36ebcb3b1215 100644
--- a/arch/score/kernel/vmlinux.lds.S
+++ b/arch/score/kernel/vmlinux.lds.S
@@ -41,7 +41,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		*(.text.*)
 		*(.fixup)
 		. = ALIGN (4) ;
diff --git a/arch/sh/kernel/vmlinux.lds.S b/arch/sh/kernel/vmlinux.lds.S
index 235a4101999f..d8ae0a60cdf2 100644
--- a/arch/sh/kernel/vmlinux.lds.S
+++ b/arch/sh/kernel/vmlinux.lds.S
@@ -37,7 +37,6 @@ SECTIONS
 		EXTRA_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		*(.fixup)
diff --git a/arch/sparc/kernel/vmlinux.lds.S b/arch/sparc/kernel/vmlinux.lds.S
index d79b3b734245..017eb4d7ccca 100644
--- a/arch/sparc/kernel/vmlinux.lds.S
+++ b/arch/sparc/kernel/vmlinux.lds.S
@@ -50,7 +50,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		*(.gnu.warning)
diff --git a/arch/sparc/mm/ultra.S b/arch/sparc/mm/ultra.S
index b4f4733abc6e..6762b7db82c4 100644
--- a/arch/sparc/mm/ultra.S
+++ b/arch/sparc/mm/ultra.S
@@ -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"
+	section_rng(SECTION_TEXT, kprobes, ax)
 	.align		32
 	.globl		__flush_icache_page
 __flush_icache_page:	/* %o0 = phys_page */
diff --git a/arch/tile/kernel/vmlinux.lds.S b/arch/tile/kernel/vmlinux.lds.S
index 9d449caf8910..c222cea90b7a 100644
--- a/arch/tile/kernel/vmlinux.lds.S
+++ b/arch/tile/kernel/vmlinux.lds.S
@@ -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 */
diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
index 7847e5c0e0b5..5a08b2e7196d 100644
--- a/arch/x86/kernel/kprobes/core.c
+++ b/arch/x86/kernel/kprobes/core.c
@@ -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)
diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
index 9297a002d8e5..8a5dfa38fde3 100644
--- a/arch/x86/kernel/vmlinux.lds.S
+++ b/arch/x86/kernel/vmlinux.lds.S
@@ -98,7 +98,6 @@ SECTIONS
 		TEXT_TEXT
 		SCHED_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		ENTRY_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
diff --git a/include/asm-generic/sections.h b/include/asm-generic/sections.h
index cd4313c3edf8..fa004a67ad53 100644
--- a/include/asm-generic/sections.h
+++ b/include/asm-generic/sections.h
@@ -324,7 +324,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
  */
@@ -335,7 +334,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[];
 
diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 8048242b6a76..1664050e6560 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -444,12 +444,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) = .;			\
diff --git a/include/linux/compiler.h b/include/linux/compiler.h
index d7a0b579442c..a651a4fd537d 100644
--- a/include/linux/compiler.h
+++ b/include/linux/compiler.h
@@ -544,7 +544,7 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
 
 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
 #ifdef CONFIG_KPROBES
-# define __kprobes	__attribute__((__section__(".kprobes.text")))
+# define __kprobes	__LINUX_RANGE(SECTION_TEXT, kprobes)
 # define nokprobe_inline	__always_inline
 #else
 # define __kprobes
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index 8f6849084248..3f46b282a3f9 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -42,8 +42,11 @@
 #include <linux/ftrace.h>
 
 #ifdef CONFIG_KPROBES
+#include <linux/ranges.h>
 #include <asm/kprobes.h>
 
+DECLARE_SECTION_RANGE(kprobes);
+
 /* kprobe_status settings */
 #define KPROBE_HIT_ACTIVE	0x00000001
 #define KPROBE_HIT_SS		0x00000002
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index d10ab6b9b5e0..387605682622 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -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;
diff --git a/scripts/Makefile b/scripts/Makefile
index 1d80897a9644..77a0cc91628c 100644
--- a/scripts/Makefile
+++ b/scripts/Makefile
@@ -10,6 +10,7 @@
 # check-lc_ctype: Used in Documentation/DocBook
 
 HOST_EXTRACFLAGS += -I$(srctree)/tools/include
+HOST_EXTRACFLAGS += -U__KERNEL__
 
 hostprogs-$(CONFIG_KALLSYMS)     += kallsyms
 hostprogs-$(CONFIG_LOGO)         += pnmtologo
diff --git a/scripts/mod/Makefile b/scripts/mod/Makefile
index 8257ef422c0a..76905d4ac0d0 100644
--- a/scripts/mod/Makefile
+++ b/scripts/mod/Makefile
@@ -1,5 +1,7 @@
 OBJECT_FILES_NON_STANDARD := y
 
+HOST_EXTRACFLAGS += -U__KERNEL__
+
 hostprogs-y	:= modpost mk_elfconfig
 always		:= $(hostprogs-y) empty.o
 
diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
index 48958d3cec9e..12ddced5df84 100644
--- a/scripts/mod/modpost.c
+++ b/scripts/mod/modpost.c
@@ -19,10 +19,16 @@
 #include <stdbool.h>
 #include <errno.h>
 #include "modpost.h"
+
 #include "../../include/generated/autoconf.h"
 #include "../../include/linux/license.h"
 #include "../../include/linux/export.h"
 
+#include "../../include/linux/sections.h"
+#include "../../include/asm-generic/sections.h"
+#include "../../include/linux/ranges.h"
+#include "../../include/asm-generic/ranges.h"
+
 /* Are we using CONFIG_MODVERSIONS? */
 static int modversions = 0;
 /* Warn about undefined symbols? (do so if we have vmlinux) */
@@ -888,7 +894,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"
+		SECTION_RNG(SECTION_TEXT, kprobes)
 #define OTHER_TEXT_SECTIONS ".ref.text", ".head.text", ".spinlock.text", \
 		".fixup", ".entry.text", ".exception.text", ".text.*", \
 		".coldtext"
diff --git a/scripts/recordmcount.c b/scripts/recordmcount.c
index e167592793a7..8381d75235d4 100644
--- a/scripts/recordmcount.c
+++ b/scripts/recordmcount.c
@@ -33,6 +33,11 @@
 #include <string.h>
 #include <unistd.h>
 
+#include "../../include/linux/sections.h"
+#include "../../include/asm-generic/sections.h"
+#include "../../include/linux/ranges.h"
+#include "../../include/asm-generic/ranges.h"
+
 #ifndef EM_METAG
 /* Remove this when these make it to the standard system elf.h. */
 #define EM_METAG      174
@@ -356,7 +361,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(SECTION_RNG(SECTION_TEXT, kprobe), txtname) == 0 ||
 		strcmp(".text.unlikely", txtname) == 0;
 }
 
diff --git a/scripts/recordmcount.pl b/scripts/recordmcount.pl
index 96e2486a6fc4..f663a7c5d6ab 100755
--- a/scripts/recordmcount.pl
+++ b/scripts/recordmcount.pl
@@ -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,
 );
 
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 13/13] kprobes: port blacklist kprobes to linker table
  2016-07-22 21:24 ` Luis R. Rodriguez
  (?)
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 include/asm-generic/vmlinux.lds.h | 10 ----------
 include/linux/kprobes.h           |  5 +++--
 kernel/kprobes.c                  | 11 ++++-------
 3 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 1664050e6560..0e4df8c61c18 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -113,15 +113,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) = .;	\
@@ -519,7 +510,6 @@
 	*(SECTION_INIT_RODATA)						\
 	FTRACE_EVENTS()							\
 	TRACE_SYSCALLS()						\
-	KPROBE_BLACKLIST()						\
 	MEM_DISCARD(init.rodata)					\
 	CLK_OF_TABLES()							\
 	RESERVEDMEM_OF_TABLES()						\
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index 3f46b282a3f9..c9bb9caef70c 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -43,9 +43,11 @@
 
 #ifdef CONFIG_KPROBES
 #include <linux/ranges.h>
+#include <linux/tables.h>
 #include <asm/kprobes.h>
 
 DECLARE_SECTION_RANGE(kprobes);
+DECLARE_LINKTABLE(unsigned long, _kprobe_blacklist);
 
 /* kprobe_status settings */
 #define KPROBE_HIT_ACTIVE	0x00000001
@@ -490,8 +492,7 @@ static inline int enable_jprobe(struct jprobe *jp)
  * 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)
 #else
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 387605682622..4801aa3b4adf 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -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");
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 13/13] kprobes: port blacklist kprobes to linker table
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 include/asm-generic/vmlinux.lds.h | 10 ----------
 include/linux/kprobes.h           |  5 +++--
 kernel/kprobes.c                  | 11 ++++-------
 3 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 1664050e6560..0e4df8c61c18 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -113,15 +113,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) = .;	\
@@ -519,7 +510,6 @@
 	*(SECTION_INIT_RODATA)						\
 	FTRACE_EVENTS()							\
 	TRACE_SYSCALLS()						\
-	KPROBE_BLACKLIST()						\
 	MEM_DISCARD(init.rodata)					\
 	CLK_OF_TABLES()							\
 	RESERVEDMEM_OF_TABLES()						\
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index 3f46b282a3f9..c9bb9caef70c 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -43,9 +43,11 @@
 
 #ifdef CONFIG_KPROBES
 #include <linux/ranges.h>
+#include <linux/tables.h>
 #include <asm/kprobes.h>
 
 DECLARE_SECTION_RANGE(kprobes);
+DECLARE_LINKTABLE(unsigned long, _kprobe_blacklist);
 
 /* kprobe_status settings */
 #define KPROBE_HIT_ACTIVE	0x00000001
@@ -490,8 +492,7 @@ static inline int enable_jprobe(struct jprobe *jp)
  * 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)
 #else
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 387605682622..4801aa3b4adf 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -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");
-- 
2.8.4

^ permalink raw reply related	[flat|nested] 176+ messages in thread

* [RFC v3 13/13] kprobes: port blacklist kprobes to linker table
@ 2016-07-22 21:24   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:24 UTC (permalink / raw)
  To: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6
  Cc: x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe, Luis R. Rodriguez

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

Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
---
 include/asm-generic/vmlinux.lds.h | 10 ----------
 include/linux/kprobes.h           |  5 +++--
 kernel/kprobes.c                  | 11 ++++-------
 3 files changed, 7 insertions(+), 19 deletions(-)

diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
index 1664050e6560..0e4df8c61c18 100644
--- a/include/asm-generic/vmlinux.lds.h
+++ b/include/asm-generic/vmlinux.lds.h
@@ -113,15 +113,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) = .;	\
@@ -519,7 +510,6 @@
 	*(SECTION_INIT_RODATA)						\
 	FTRACE_EVENTS()							\
 	TRACE_SYSCALLS()						\
-	KPROBE_BLACKLIST()						\
 	MEM_DISCARD(init.rodata)					\
 	CLK_OF_TABLES()							\
 	RESERVEDMEM_OF_TABLES()						\
diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
index 3f46b282a3f9..c9bb9caef70c 100644
--- a/include/linux/kprobes.h
+++ b/include/linux/kprobes.h
@@ -43,9 +43,11 @@
 
 #ifdef CONFIG_KPROBES
 #include <linux/ranges.h>
+#include <linux/tables.h>
 #include <asm/kprobes.h>
 
 DECLARE_SECTION_RANGE(kprobes);
+DECLARE_LINKTABLE(unsigned long, _kprobe_blacklist);
 
 /* kprobe_status settings */
 #define KPROBE_HIT_ACTIVE	0x00000001
@@ -490,8 +492,7 @@ static inline int enable_jprobe(struct jprobe *jp)
  * 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)
 #else
diff --git a/kernel/kprobes.c b/kernel/kprobes.c
index 387605682622..4801aa3b4adf 100644
--- a/kernel/kprobes.c
+++ b/kernel/kprobes.c
@@ -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");
-- 
2.8.4


^ permalink raw reply related	[flat|nested] 176+ messages in thread

* Re: [RFC v3 02/13] dell-smo8800: include uaccess.h
  2016-07-22 21:24   ` Luis R. Rodriguez
  (?)
@ 2016-07-22 21:31     ` Pali Rohár
  -1 siblings, 0 replies; 176+ messages in thread
From: Pali Rohár @ 2016-07-22 21:31 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6, x86, luto, keescook, torvalds, gregkh, rusty, gnomes,
	alan, dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker

[-- Attachment #1: Type: Text/Plain, Size: 1176 bytes --]

On Friday 22 July 2016 23:24:36 Luis R. Rodriguez wrote:
> 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
> 
> Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
> ---
>  drivers/platform/x86/dell-smo8800.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/platform/x86/dell-smo8800.c
> b/drivers/platform/x86/dell-smo8800.c index
> 0aec4fd4c48e..37e646034ef8 100644
> --- a/drivers/platform/x86/dell-smo8800.c
> +++ b/drivers/platform/x86/dell-smo8800.c
> @@ -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 */

This is trivial change for dell-smo8800, so you can add my Reviewed-by.

-- 
Pali Rohár
pali.rohar@gmail.com

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 02/13] dell-smo8800: include uaccess.h
@ 2016-07-22 21:31     ` Pali Rohár
  0 siblings, 0 replies; 176+ messages in thread
From: Pali Rohár @ 2016-07-22 21:31 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6, x86, luto, keescook, torvalds, gregkh, rusty, gnomes,
	alan, dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker

[-- Attachment #1: Type: Text/Plain, Size: 1176 bytes --]

On Friday 22 July 2016 23:24:36 Luis R. Rodriguez wrote:
> 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
> 
> Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
> ---
>  drivers/platform/x86/dell-smo8800.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/platform/x86/dell-smo8800.c
> b/drivers/platform/x86/dell-smo8800.c index
> 0aec4fd4c48e..37e646034ef8 100644
> --- a/drivers/platform/x86/dell-smo8800.c
> +++ b/drivers/platform/x86/dell-smo8800.c
> @@ -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 */

This is trivial change for dell-smo8800, so you can add my Reviewed-by.

-- 
Pali Rohár
pali.rohar@gmail.com

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 02/13] dell-smo8800: include uaccess.h
@ 2016-07-22 21:31     ` Pali Rohár
  0 siblings, 0 replies; 176+ messages in thread
From: Pali Rohár @ 2016-07-22 21:31 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6, x86, luto, keescook, torvalds, gregkh, rusty, gnomes,
	alan, dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, dvhart, platform-driver-x86,
	mmarek, linux, jkosina, korea.drzix, linux-kbuild, tony.luck,
	akpm, linux-ia64, linux-arm-kernel, linux-sh, sparclinux,
	catalin.marinas, will.deacon, rostedt, jpoimboe

[-- Attachment #1: Type: Text/Plain, Size: 1176 bytes --]

On Friday 22 July 2016 23:24:36 Luis R. Rodriguez wrote:
> 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
> 
> Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
> ---
>  drivers/platform/x86/dell-smo8800.c | 1 +
>  1 file changed, 1 insertion(+)
> 
> diff --git a/drivers/platform/x86/dell-smo8800.c
> b/drivers/platform/x86/dell-smo8800.c index
> 0aec4fd4c48e..37e646034ef8 100644
> --- a/drivers/platform/x86/dell-smo8800.c
> +++ b/drivers/platform/x86/dell-smo8800.c
> @@ -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 */

This is trivial change for dell-smo8800, so you can add my Reviewed-by.

-- 
Pali Rohár
pali.rohar@gmail.com

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 198 bytes --]

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 05/13] sections.h: add sections header to collect all section info
  2016-07-22 21:24   ` Luis R. Rodriguez
  (?)
@ 2016-07-22 21:37     ` James Hogan
  -1 siblings, 0 replies; 176+ messages in thread
From: James Hogan @ 2016-07-22 21:37 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6, x86, luto, keescook, torvalds, gregkh, rusty, gnomes,
	alan, dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker

[-- Attachment #1: Type: text/plain, Size: 1338 bytes --]

Hi Luis,

On Friday 22 July 2016 14:24:39 Luis R. Rodriguez wrote:
>  arch/alpha/include/asm/sections.h     |   6 +
>  arch/arm64/include/asm/sections.h     |   6 +
>  arch/avr32/include/asm/sections.h     |   6 +
>  arch/cris/include/asm/sections.h      |   6 +
>  arch/h8300/include/asm/sections.h     |   6 +
>  arch/hexagon/include/asm/sections.h   |   6 +
>  arch/m32r/include/asm/sections.h      |   6 +
>  arch/m68k/include/asm/sections.h      |   6 +
>  arch/metag/include/asm/sections.h     |   6 +
>  arch/mips/include/asm/sections.h      |   6 +
>  arch/mn10300/include/asm/sections.h   |   6 +
>  arch/nios2/include/asm/sections.h     |   6 +
>  arch/openrisc/include/asm/sections.h  |   6 +
>  arch/score/include/asm/sections.h     |   6 +
>  arch/unicore32/include/asm/sections.h |   6 +
>  arch/xtensa/include/asm/sections.h    |   6 +

> diff --git a/arch/alpha/include/asm/sections.h b/arch/alpha/include/asm/sections.h
> new file mode 100644
> index 000000000000..e58fc679fe15
> --- /dev/null
> +++ b/arch/alpha/include/asm/sections.h
> @@ -0,0 +1,6 @@
> +#ifndef _ASM_ALPHA_SECTIONS_H
> +#define _ASM_ALPHA_SECTIONS_H
> +
> +#include <asm-generic/sections.h>
> +
> +#endif /* _ASM_ALPHA_SECTIONS_H */

Any particular reason not to use generic-y in the Kbuild files for
sections.h, ranges.h, and tables.h?

Cheers
James

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 05/13] sections.h: add sections header to collect all section info
@ 2016-07-22 21:37     ` James Hogan
  0 siblings, 0 replies; 176+ messages in thread
From: James Hogan @ 2016-07-22 21:37 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6, x86, luto, keescook, torvalds, gregkh, rusty, gnomes,
	alan, dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker

[-- Attachment #1: Type: text/plain, Size: 1338 bytes --]

Hi Luis,

On Friday 22 July 2016 14:24:39 Luis R. Rodriguez wrote:
>  arch/alpha/include/asm/sections.h     |   6 +
>  arch/arm64/include/asm/sections.h     |   6 +
>  arch/avr32/include/asm/sections.h     |   6 +
>  arch/cris/include/asm/sections.h      |   6 +
>  arch/h8300/include/asm/sections.h     |   6 +
>  arch/hexagon/include/asm/sections.h   |   6 +
>  arch/m32r/include/asm/sections.h      |   6 +
>  arch/m68k/include/asm/sections.h      |   6 +
>  arch/metag/include/asm/sections.h     |   6 +
>  arch/mips/include/asm/sections.h      |   6 +
>  arch/mn10300/include/asm/sections.h   |   6 +
>  arch/nios2/include/asm/sections.h     |   6 +
>  arch/openrisc/include/asm/sections.h  |   6 +
>  arch/score/include/asm/sections.h     |   6 +
>  arch/unicore32/include/asm/sections.h |   6 +
>  arch/xtensa/include/asm/sections.h    |   6 +

> diff --git a/arch/alpha/include/asm/sections.h b/arch/alpha/include/asm/sections.h
> new file mode 100644
> index 000000000000..e58fc679fe15
> --- /dev/null
> +++ b/arch/alpha/include/asm/sections.h
> @@ -0,0 +1,6 @@
> +#ifndef _ASM_ALPHA_SECTIONS_H
> +#define _ASM_ALPHA_SECTIONS_H
> +
> +#include <asm-generic/sections.h>
> +
> +#endif /* _ASM_ALPHA_SECTIONS_H */

Any particular reason not to use generic-y in the Kbuild files for
sections.h, ranges.h, and tables.h?

Cheers
James

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 05/13] sections.h: add sections header to collect all section info
@ 2016-07-22 21:37     ` James Hogan
  0 siblings, 0 replies; 176+ messages in thread
From: James Hogan @ 2016-07-22 21:37 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6, x86, luto, keescook, torvalds, gregkh, rusty, gnomes,
	alan, dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe

[-- Attachment #1: Type: text/plain, Size: 1338 bytes --]

Hi Luis,

On Friday 22 July 2016 14:24:39 Luis R. Rodriguez wrote:
>  arch/alpha/include/asm/sections.h     |   6 +
>  arch/arm64/include/asm/sections.h     |   6 +
>  arch/avr32/include/asm/sections.h     |   6 +
>  arch/cris/include/asm/sections.h      |   6 +
>  arch/h8300/include/asm/sections.h     |   6 +
>  arch/hexagon/include/asm/sections.h   |   6 +
>  arch/m32r/include/asm/sections.h      |   6 +
>  arch/m68k/include/asm/sections.h      |   6 +
>  arch/metag/include/asm/sections.h     |   6 +
>  arch/mips/include/asm/sections.h      |   6 +
>  arch/mn10300/include/asm/sections.h   |   6 +
>  arch/nios2/include/asm/sections.h     |   6 +
>  arch/openrisc/include/asm/sections.h  |   6 +
>  arch/score/include/asm/sections.h     |   6 +
>  arch/unicore32/include/asm/sections.h |   6 +
>  arch/xtensa/include/asm/sections.h    |   6 +

> diff --git a/arch/alpha/include/asm/sections.h b/arch/alpha/include/asm/sections.h
> new file mode 100644
> index 000000000000..e58fc679fe15
> --- /dev/null
> +++ b/arch/alpha/include/asm/sections.h
> @@ -0,0 +1,6 @@
> +#ifndef _ASM_ALPHA_SECTIONS_H
> +#define _ASM_ALPHA_SECTIONS_H
> +
> +#include <asm-generic/sections.h>
> +
> +#endif /* _ASM_ALPHA_SECTIONS_H */

Any particular reason not to use generic-y in the Kbuild files for
sections.h, ranges.h, and tables.h?

Cheers
James

[-- Attachment #2: This is a digitally signed message part. --]
[-- Type: application/pgp-signature, Size: 819 bytes --]

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 05/13] sections.h: add sections header to collect all section info
  2016-07-22 21:37     ` James Hogan
  (?)
@ 2016-07-22 21:41       ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:41 UTC (permalink / raw)
  To: James Hogan
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevche

On Fri, Jul 22, 2016 at 10:37:16PM +0100, James Hogan wrote:
> Hi Luis,
> 
> On Friday 22 July 2016 14:24:39 Luis R. Rodriguez wrote:
> >  arch/alpha/include/asm/sections.h     |   6 +
> >  arch/arm64/include/asm/sections.h     |   6 +
> >  arch/avr32/include/asm/sections.h     |   6 +
> >  arch/cris/include/asm/sections.h      |   6 +
> >  arch/h8300/include/asm/sections.h     |   6 +
> >  arch/hexagon/include/asm/sections.h   |   6 +
> >  arch/m32r/include/asm/sections.h      |   6 +
> >  arch/m68k/include/asm/sections.h      |   6 +
> >  arch/metag/include/asm/sections.h     |   6 +
> >  arch/mips/include/asm/sections.h      |   6 +
> >  arch/mn10300/include/asm/sections.h   |   6 +
> >  arch/nios2/include/asm/sections.h     |   6 +
> >  arch/openrisc/include/asm/sections.h  |   6 +
> >  arch/score/include/asm/sections.h     |   6 +
> >  arch/unicore32/include/asm/sections.h |   6 +
> >  arch/xtensa/include/asm/sections.h    |   6 +
> 
> > diff --git a/arch/alpha/include/asm/sections.h b/arch/alpha/include/asm/sections.h
> > new file mode 100644
> > index 000000000000..e58fc679fe15
> > --- /dev/null
> > +++ b/arch/alpha/include/asm/sections.h
> > @@ -0,0 +1,6 @@
> > +#ifndef _ASM_ALPHA_SECTIONS_H
> > +#define _ASM_ALPHA_SECTIONS_H
> > +
> > +#include <asm-generic/sections.h>
> > +
> > +#endif /* _ASM_ALPHA_SECTIONS_H */
> 
> Any particular reason not to use generic-y in the Kbuild files for
> sections.h, ranges.h, and tables.h?

I was just not aware of that, thanks, will do this in the next iteration!

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 05/13] sections.h: add sections header to collect all section info
@ 2016-07-22 21:41       ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:41 UTC (permalink / raw)
  To: James Hogan
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevche

On Fri, Jul 22, 2016 at 10:37:16PM +0100, James Hogan wrote:
> Hi Luis,
> 
> On Friday 22 July 2016 14:24:39 Luis R. Rodriguez wrote:
> >  arch/alpha/include/asm/sections.h     |   6 +
> >  arch/arm64/include/asm/sections.h     |   6 +
> >  arch/avr32/include/asm/sections.h     |   6 +
> >  arch/cris/include/asm/sections.h      |   6 +
> >  arch/h8300/include/asm/sections.h     |   6 +
> >  arch/hexagon/include/asm/sections.h   |   6 +
> >  arch/m32r/include/asm/sections.h      |   6 +
> >  arch/m68k/include/asm/sections.h      |   6 +
> >  arch/metag/include/asm/sections.h     |   6 +
> >  arch/mips/include/asm/sections.h      |   6 +
> >  arch/mn10300/include/asm/sections.h   |   6 +
> >  arch/nios2/include/asm/sections.h     |   6 +
> >  arch/openrisc/include/asm/sections.h  |   6 +
> >  arch/score/include/asm/sections.h     |   6 +
> >  arch/unicore32/include/asm/sections.h |   6 +
> >  arch/xtensa/include/asm/sections.h    |   6 +
> 
> > diff --git a/arch/alpha/include/asm/sections.h b/arch/alpha/include/asm/sections.h
> > new file mode 100644
> > index 000000000000..e58fc679fe15
> > --- /dev/null
> > +++ b/arch/alpha/include/asm/sections.h
> > @@ -0,0 +1,6 @@
> > +#ifndef _ASM_ALPHA_SECTIONS_H
> > +#define _ASM_ALPHA_SECTIONS_H
> > +
> > +#include <asm-generic/sections.h>
> > +
> > +#endif /* _ASM_ALPHA_SECTIONS_H */
> 
> Any particular reason not to use generic-y in the Kbuild files for
> sections.h, ranges.h, and tables.h?

I was just not aware of that, thanks, will do this in the next iteration!

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 05/13] sections.h: add sections header to collect all section info
@ 2016-07-22 21:41       ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 21:41 UTC (permalink / raw)
  To: James Hogan
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker, xen-devel, ak,
	pali.rohar, dvhart, platform-driver-x86, mmarek, linux, jkosina,
	korea.drzix, linux-kbuild, tony.luck, akpm, linux-ia64,
	linux-arm-kernel, linux-sh, sparclinux, catalin.marinas,
	will.deacon, rostedt, jpoimboe

On Fri, Jul 22, 2016 at 10:37:16PM +0100, James Hogan wrote:
> Hi Luis,
> 
> On Friday 22 July 2016 14:24:39 Luis R. Rodriguez wrote:
> >  arch/alpha/include/asm/sections.h     |   6 +
> >  arch/arm64/include/asm/sections.h     |   6 +
> >  arch/avr32/include/asm/sections.h     |   6 +
> >  arch/cris/include/asm/sections.h      |   6 +
> >  arch/h8300/include/asm/sections.h     |   6 +
> >  arch/hexagon/include/asm/sections.h   |   6 +
> >  arch/m32r/include/asm/sections.h      |   6 +
> >  arch/m68k/include/asm/sections.h      |   6 +
> >  arch/metag/include/asm/sections.h     |   6 +
> >  arch/mips/include/asm/sections.h      |   6 +
> >  arch/mn10300/include/asm/sections.h   |   6 +
> >  arch/nios2/include/asm/sections.h     |   6 +
> >  arch/openrisc/include/asm/sections.h  |   6 +
> >  arch/score/include/asm/sections.h     |   6 +
> >  arch/unicore32/include/asm/sections.h |   6 +
> >  arch/xtensa/include/asm/sections.h    |   6 +
> 
> > diff --git a/arch/alpha/include/asm/sections.h b/arch/alpha/include/asm/sections.h
> > new file mode 100644
> > index 000000000000..e58fc679fe15
> > --- /dev/null
> > +++ b/arch/alpha/include/asm/sections.h
> > @@ -0,0 +1,6 @@
> > +#ifndef _ASM_ALPHA_SECTIONS_H
> > +#define _ASM_ALPHA_SECTIONS_H
> > +
> > +#include <asm-generic/sections.h>
> > +
> > +#endif /* _ASM_ALPHA_SECTIONS_H */
> 
> Any particular reason not to use generic-y in the Kbuild files for
> sections.h, ranges.h, and tables.h?

I was just not aware of that, thanks, will do this in the next iteration!

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 10/13] jump_label: port __jump_table to linker tables
  2016-07-22 21:24   ` Luis R. Rodriguez
  (?)
@ 2016-07-22 21:49     ` Josh Poimboeuf
  -1 siblings, 0 replies; 176+ messages in thread
From: Josh Poimboeuf @ 2016-07-22 21:49 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6, x86, luto, keescook, torvalds, gregkh, rusty, gnomes,
	alan, dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker

On Fri, Jul 22, 2016 at 02:24:44PM -0700, Luis R. Rodriguez wrote:
> diff --git a/tools/objtool/special.c b/tools/objtool/special.c
> index bff8abb3a4aa..f0ad369f994b 100644
> --- a/tools/objtool/special.c
> +++ b/tools/objtool/special.c
> @@ -26,6 +26,10 @@
>  #include "special.h"
>  #include "warn.h"
>  
> +#include "../../include/asm-generic/sections.h"
> +#include "../../include/asm-generic/tables.h"
> +#include "../../include/linux/stringify.h"
> +
>  #define EX_ENTRY_SIZE		12
>  #define EX_ORIG_OFFSET		0
>  #define EX_NEW_OFFSET		4
> @@ -63,7 +67,9 @@ struct special_entry entries[] = {
>  		.feature = ALT_FEATURE_OFFSET,
>  	},
>  	{
> -		.sec = "__jump_table",
> +		.sec = __stringify(SECTION_TBL(SECTION_DATA,
> +				               __jump_table,
> +					       SECTION_ORDER_ANY)),
>  		.jump_or_nop = true,
>  		.size = JUMP_ENTRY_SIZE,
>  		.orig = JUMP_ORIG_OFFSET,

(continuing our discussion from another thread...)

I think tools code isn't allowed to include kernel files because the
tools subdirectory is supposed to be completely independent.
 
As far as I can tell, the section name will always be
".data.tbl.__jump_table.any".  Is that true?  If so, any reason why we
can't just hard-code the string here?  As you saw, if the string
changes, objtool will complain and 0-day will report it.

-- 
Josh

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 10/13] jump_label: port __jump_table to linker tables
@ 2016-07-22 21:49     ` Josh Poimboeuf
  0 siblings, 0 replies; 176+ messages in thread
From: Josh Poimboeuf @ 2016-07-22 21:49 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6, x86, luto, keescook, torvalds, gregkh, rusty, gnomes,
	alan, dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker

On Fri, Jul 22, 2016 at 02:24:44PM -0700, Luis R. Rodriguez wrote:
> diff --git a/tools/objtool/special.c b/tools/objtool/special.c
> index bff8abb3a4aa..f0ad369f994b 100644
> --- a/tools/objtool/special.c
> +++ b/tools/objtool/special.c
> @@ -26,6 +26,10 @@
>  #include "special.h"
>  #include "warn.h"
>  
> +#include "../../include/asm-generic/sections.h"
> +#include "../../include/asm-generic/tables.h"
> +#include "../../include/linux/stringify.h"
> +
>  #define EX_ENTRY_SIZE		12
>  #define EX_ORIG_OFFSET		0
>  #define EX_NEW_OFFSET		4
> @@ -63,7 +67,9 @@ struct special_entry entries[] = {
>  		.feature = ALT_FEATURE_OFFSET,
>  	},
>  	{
> -		.sec = "__jump_table",
> +		.sec = __stringify(SECTION_TBL(SECTION_DATA,
> +				               __jump_table,
> +					       SECTION_ORDER_ANY)),
>  		.jump_or_nop = true,
>  		.size = JUMP_ENTRY_SIZE,
>  		.orig = JUMP_ORIG_OFFSET,

(continuing our discussion from another thread...)

I think tools code isn't allowed to include kernel files because the
tools subdirectory is supposed to be completely independent.
 
As far as I can tell, the section name will always be
".data.tbl.__jump_table.any".  Is that true?  If so, any reason why we
can't just hard-code the string here?  As you saw, if the string
changes, objtool will complain and 0-day will report it.

-- 
Josh

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 10/13] jump_label: port __jump_table to linker tables
@ 2016-07-22 21:49     ` Josh Poimboeuf
  0 siblings, 0 replies; 176+ messages in thread
From: Josh Poimboeuf @ 2016-07-22 21:49 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6, x86, luto, keescook, torvalds, gregkh, rusty, gnomes,
	alan, dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt

On Fri, Jul 22, 2016 at 02:24:44PM -0700, Luis R. Rodriguez wrote:
> diff --git a/tools/objtool/special.c b/tools/objtool/special.c
> index bff8abb3a4aa..f0ad369f994b 100644
> --- a/tools/objtool/special.c
> +++ b/tools/objtool/special.c
> @@ -26,6 +26,10 @@
>  #include "special.h"
>  #include "warn.h"
>  
> +#include "../../include/asm-generic/sections.h"
> +#include "../../include/asm-generic/tables.h"
> +#include "../../include/linux/stringify.h"
> +
>  #define EX_ENTRY_SIZE		12
>  #define EX_ORIG_OFFSET		0
>  #define EX_NEW_OFFSET		4
> @@ -63,7 +67,9 @@ struct special_entry entries[] = {
>  		.feature = ALT_FEATURE_OFFSET,
>  	},
>  	{
> -		.sec = "__jump_table",
> +		.sec = __stringify(SECTION_TBL(SECTION_DATA,
> +				               __jump_table,
> +					       SECTION_ORDER_ANY)),
>  		.jump_or_nop = true,
>  		.size = JUMP_ENTRY_SIZE,
>  		.orig = JUMP_ORIG_OFFSET,

(continuing our discussion from another thread...)

I think tools code isn't allowed to include kernel files because the
tools subdirectory is supposed to be completely independent.
 
As far as I can tell, the section name will always be
".data.tbl.__jump_table.any".  Is that true?  If so, any reason why we
can't just hard-code the string here?  As you saw, if the string
changes, objtool will complain and 0-day will report it.

-- 
Josh

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 10/13] jump_label: port __jump_table to linker tables
  2016-07-22 21:49     ` Josh Poimboeuf
  (?)
@ 2016-07-22 22:26       ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 22:26 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevche

On Fri, Jul 22, 2016 at 04:49:45PM -0500, Josh Poimboeuf wrote:
> On Fri, Jul 22, 2016 at 02:24:44PM -0700, Luis R. Rodriguez wrote:
> > diff --git a/tools/objtool/special.c b/tools/objtool/special.c
> > index bff8abb3a4aa..f0ad369f994b 100644
> > --- a/tools/objtool/special.c
> > +++ b/tools/objtool/special.c
> > @@ -26,6 +26,10 @@
> >  #include "special.h"
> >  #include "warn.h"
> >  
> > +#include "../../include/asm-generic/sections.h"
> > +#include "../../include/asm-generic/tables.h"
> > +#include "../../include/linux/stringify.h"
> > +
> >  #define EX_ENTRY_SIZE		12
> >  #define EX_ORIG_OFFSET		0
> >  #define EX_NEW_OFFSET		4
> > @@ -63,7 +67,9 @@ struct special_entry entries[] = {
> >  		.feature = ALT_FEATURE_OFFSET,
> >  	},
> >  	{
> > -		.sec = "__jump_table",
> > +		.sec = __stringify(SECTION_TBL(SECTION_DATA,
> > +				               __jump_table,
> > +					       SECTION_ORDER_ANY)),
> >  		.jump_or_nop = true,
> >  		.size = JUMP_ENTRY_SIZE,
> >  		.orig = JUMP_ORIG_OFFSET,
> 
> (continuing our discussion from another thread...)
> 
> I think tools code isn't allowed to include kernel files because the
> tools subdirectory is supposed to be completely independent.

That was also the case for userpsace tools in scripts/ -- for instance
scripts/mod/modpost.c made an exception. What I've proposed here to
keep things simple was to ensure -UKERNEL is passed and then only
include files we know will work.

Refer to the patch "kprobes: port .kprobes.text to section range"
in this series for an extension of the scripts/mod/modpost.c kernel
headers use.

> As far as I can tell, the section name will always be
> ".data.tbl.__jump_table.any".  Is that true?  If so, any reason why we
> can't just hard-code the string here?

Its a fair strategy, however if upstream changes the order name we'd
have to hand code this as well, by using a macro we keep it all in one
place.

> As you saw, if the string
> changes, objtool will complain and 0-day will report it.

Indeed, which is why I was hoping to instead stick to a standard
sections set of header files that lets us get these in on place.
The only place I hand coded in this series was in the perl
file scripts/recordmcount.pl but I suppose if we wanted to get
creative we could even generate a header for it too.

If we want to avoid all this hacker include stuff another option
is to *generate* each respective sections.h for the kernel, and
also, one for tools, and one for perl. What do you think?

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 10/13] jump_label: port __jump_table to linker tables
@ 2016-07-22 22:26       ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 22:26 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevche

On Fri, Jul 22, 2016 at 04:49:45PM -0500, Josh Poimboeuf wrote:
> On Fri, Jul 22, 2016 at 02:24:44PM -0700, Luis R. Rodriguez wrote:
> > diff --git a/tools/objtool/special.c b/tools/objtool/special.c
> > index bff8abb3a4aa..f0ad369f994b 100644
> > --- a/tools/objtool/special.c
> > +++ b/tools/objtool/special.c
> > @@ -26,6 +26,10 @@
> >  #include "special.h"
> >  #include "warn.h"
> >  
> > +#include "../../include/asm-generic/sections.h"
> > +#include "../../include/asm-generic/tables.h"
> > +#include "../../include/linux/stringify.h"
> > +
> >  #define EX_ENTRY_SIZE		12
> >  #define EX_ORIG_OFFSET		0
> >  #define EX_NEW_OFFSET		4
> > @@ -63,7 +67,9 @@ struct special_entry entries[] = {
> >  		.feature = ALT_FEATURE_OFFSET,
> >  	},
> >  	{
> > -		.sec = "__jump_table",
> > +		.sec = __stringify(SECTION_TBL(SECTION_DATA,
> > +				               __jump_table,
> > +					       SECTION_ORDER_ANY)),
> >  		.jump_or_nop = true,
> >  		.size = JUMP_ENTRY_SIZE,
> >  		.orig = JUMP_ORIG_OFFSET,
> 
> (continuing our discussion from another thread...)
> 
> I think tools code isn't allowed to include kernel files because the
> tools subdirectory is supposed to be completely independent.

That was also the case for userpsace tools in scripts/ -- for instance
scripts/mod/modpost.c made an exception. What I've proposed here to
keep things simple was to ensure -UKERNEL is passed and then only
include files we know will work.

Refer to the patch "kprobes: port .kprobes.text to section range"
in this series for an extension of the scripts/mod/modpost.c kernel
headers use.

> As far as I can tell, the section name will always be
> ".data.tbl.__jump_table.any".  Is that true?  If so, any reason why we
> can't just hard-code the string here?

Its a fair strategy, however if upstream changes the order name we'd
have to hand code this as well, by using a macro we keep it all in one
place.

> As you saw, if the string
> changes, objtool will complain and 0-day will report it.

Indeed, which is why I was hoping to instead stick to a standard
sections set of header files that lets us get these in on place.
The only place I hand coded in this series was in the perl
file scripts/recordmcount.pl but I suppose if we wanted to get
creative we could even generate a header for it too.

If we want to avoid all this hacker include stuff another option
is to *generate* each respective sections.h for the kernel, and
also, one for tools, and one for perl. What do you think?

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 10/13] jump_label: port __jump_table to linker tables
@ 2016-07-22 22:26       ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-22 22:26 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker, xen-devel, ak,
	pali.rohar, dvhart, platform-driver-x86, mmarek, linux, jkosina,
	korea.drzix, linux-kbuild, tony.luck, akpm, linux-ia64,
	linux-arm-kernel, linux-sh, sparclinux, catalin.marinas,
	will.deacon, rostedt

On Fri, Jul 22, 2016 at 04:49:45PM -0500, Josh Poimboeuf wrote:
> On Fri, Jul 22, 2016 at 02:24:44PM -0700, Luis R. Rodriguez wrote:
> > diff --git a/tools/objtool/special.c b/tools/objtool/special.c
> > index bff8abb3a4aa..f0ad369f994b 100644
> > --- a/tools/objtool/special.c
> > +++ b/tools/objtool/special.c
> > @@ -26,6 +26,10 @@
> >  #include "special.h"
> >  #include "warn.h"
> >  
> > +#include "../../include/asm-generic/sections.h"
> > +#include "../../include/asm-generic/tables.h"
> > +#include "../../include/linux/stringify.h"
> > +
> >  #define EX_ENTRY_SIZE		12
> >  #define EX_ORIG_OFFSET		0
> >  #define EX_NEW_OFFSET		4
> > @@ -63,7 +67,9 @@ struct special_entry entries[] = {
> >  		.feature = ALT_FEATURE_OFFSET,
> >  	},
> >  	{
> > -		.sec = "__jump_table",
> > +		.sec = __stringify(SECTION_TBL(SECTION_DATA,
> > +				               __jump_table,
> > +					       SECTION_ORDER_ANY)),
> >  		.jump_or_nop = true,
> >  		.size = JUMP_ENTRY_SIZE,
> >  		.orig = JUMP_ORIG_OFFSET,
> 
> (continuing our discussion from another thread...)
> 
> I think tools code isn't allowed to include kernel files because the
> tools subdirectory is supposed to be completely independent.

That was also the case for userpsace tools in scripts/ -- for instance
scripts/mod/modpost.c made an exception. What I've proposed here to
keep things simple was to ensure -UKERNEL is passed and then only
include files we know will work.

Refer to the patch "kprobes: port .kprobes.text to section range"
in this series for an extension of the scripts/mod/modpost.c kernel
headers use.

> As far as I can tell, the section name will always be
> ".data.tbl.__jump_table.any".  Is that true?  If so, any reason why we
> can't just hard-code the string here?

Its a fair strategy, however if upstream changes the order name we'd
have to hand code this as well, by using a macro we keep it all in one
place.

> As you saw, if the string
> changes, objtool will complain and 0-day will report it.

Indeed, which is why I was hoping to instead stick to a standard
sections set of header files that lets us get these in on place.
The only place I hand coded in this series was in the perl
file scripts/recordmcount.pl but I suppose if we wanted to get
creative we could even generate a header for it too.

If we want to avoid all this hacker include stuff another option
is to *generate* each respective sections.h for the kernel, and
also, one for tools, and one for perl. What do you think?

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 10/13] jump_label: port __jump_table to linker tables
  2016-07-22 22:26       ` Luis R. Rodriguez
  (?)
@ 2016-07-22 22:55         ` Josh Poimboeuf
  -1 siblings, 0 replies; 176+ messages in thread
From: Josh Poimboeuf @ 2016-07-22 22:55 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6, x86, luto, keescook, torvalds, gregkh, rusty, gnomes,
	alan, dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker

On Sat, Jul 23, 2016 at 12:26:54AM +0200, Luis R. Rodriguez wrote:
> On Fri, Jul 22, 2016 at 04:49:45PM -0500, Josh Poimboeuf wrote:
> > On Fri, Jul 22, 2016 at 02:24:44PM -0700, Luis R. Rodriguez wrote:
> > > diff --git a/tools/objtool/special.c b/tools/objtool/special.c
> > > index bff8abb3a4aa..f0ad369f994b 100644
> > > --- a/tools/objtool/special.c
> > > +++ b/tools/objtool/special.c
> > > @@ -26,6 +26,10 @@
> > >  #include "special.h"
> > >  #include "warn.h"
> > >  
> > > +#include "../../include/asm-generic/sections.h"
> > > +#include "../../include/asm-generic/tables.h"
> > > +#include "../../include/linux/stringify.h"
> > > +
> > >  #define EX_ENTRY_SIZE		12
> > >  #define EX_ORIG_OFFSET		0
> > >  #define EX_NEW_OFFSET		4
> > > @@ -63,7 +67,9 @@ struct special_entry entries[] = {
> > >  		.feature = ALT_FEATURE_OFFSET,
> > >  	},
> > >  	{
> > > -		.sec = "__jump_table",
> > > +		.sec = __stringify(SECTION_TBL(SECTION_DATA,
> > > +				               __jump_table,
> > > +					       SECTION_ORDER_ANY)),
> > >  		.jump_or_nop = true,
> > >  		.size = JUMP_ENTRY_SIZE,
> > >  		.orig = JUMP_ORIG_OFFSET,
> > 
> > (continuing our discussion from another thread...)
> > 
> > I think tools code isn't allowed to include kernel files because the
> > tools subdirectory is supposed to be completely independent.
> 
> That was also the case for userpsace tools in scripts/ -- for instance
> scripts/mod/modpost.c made an exception. What I've proposed here to
> keep things simple was to ensure -UKERNEL is passed and then only
> include files we know will work.
> 
> Refer to the patch "kprobes: port .kprobes.text to section range"
> in this series for an extension of the scripts/mod/modpost.c kernel
> headers use.

I think the rule of separating code is stricter for tools/ than it is
for scripts/.  The scripts are generally kernel-specific whereas the
tools are independent.  I believe the goal is to be able to copy them
out of the kernel tree and still be able to compile them.

> > As far as I can tell, the section name will always be
> > ".data.tbl.__jump_table.any".  Is that true?  If so, any reason why we
> > can't just hard-code the string here?
> 
> Its a fair strategy, however if upstream changes the order name we'd
> have to hand code this as well, by using a macro we keep it all in one
> place.

Hm, do you expect the section name to change often?

> > As you saw, if the string
> > changes, objtool will complain and 0-day will report it.
> 
> Indeed, which is why I was hoping to instead stick to a standard
> sections set of header files that lets us get these in on place.

Actually, I meant that obtool reporting the change would be a good
thing, in favor of just hard-coding the string.  It lets objtool do its
job of letting us know when something changes, like it did today.

> The only place I hand coded in this series was in the perl
> file scripts/recordmcount.pl but I suppose if we wanted to get
> creative we could even generate a header for it too.
> 
> If we want to avoid all this hacker include stuff another option
> is to *generate* each respective sections.h for the kernel, and
> also, one for tools, and one for perl. What do you think?

If the generated files aren't checked into git, tools/ will rely on
kernel files and will no longer be independent.  If they *are* checked
in, then we have to keep the files in sync.  Either way it sounds like
overkill, just to avoid hard-coding a string for which objtool will
already warn if it changes.

-- 
Josh

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 10/13] jump_label: port __jump_table to linker tables
@ 2016-07-22 22:55         ` Josh Poimboeuf
  0 siblings, 0 replies; 176+ messages in thread
From: Josh Poimboeuf @ 2016-07-22 22:55 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6, x86, luto, keescook, torvalds, gregkh, rusty, gnomes,
	alan, dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker

On Sat, Jul 23, 2016 at 12:26:54AM +0200, Luis R. Rodriguez wrote:
> On Fri, Jul 22, 2016 at 04:49:45PM -0500, Josh Poimboeuf wrote:
> > On Fri, Jul 22, 2016 at 02:24:44PM -0700, Luis R. Rodriguez wrote:
> > > diff --git a/tools/objtool/special.c b/tools/objtool/special.c
> > > index bff8abb3a4aa..f0ad369f994b 100644
> > > --- a/tools/objtool/special.c
> > > +++ b/tools/objtool/special.c
> > > @@ -26,6 +26,10 @@
> > >  #include "special.h"
> > >  #include "warn.h"
> > >  
> > > +#include "../../include/asm-generic/sections.h"
> > > +#include "../../include/asm-generic/tables.h"
> > > +#include "../../include/linux/stringify.h"
> > > +
> > >  #define EX_ENTRY_SIZE		12
> > >  #define EX_ORIG_OFFSET		0
> > >  #define EX_NEW_OFFSET		4
> > > @@ -63,7 +67,9 @@ struct special_entry entries[] = {
> > >  		.feature = ALT_FEATURE_OFFSET,
> > >  	},
> > >  	{
> > > -		.sec = "__jump_table",
> > > +		.sec = __stringify(SECTION_TBL(SECTION_DATA,
> > > +				               __jump_table,
> > > +					       SECTION_ORDER_ANY)),
> > >  		.jump_or_nop = true,
> > >  		.size = JUMP_ENTRY_SIZE,
> > >  		.orig = JUMP_ORIG_OFFSET,
> > 
> > (continuing our discussion from another thread...)
> > 
> > I think tools code isn't allowed to include kernel files because the
> > tools subdirectory is supposed to be completely independent.
> 
> That was also the case for userpsace tools in scripts/ -- for instance
> scripts/mod/modpost.c made an exception. What I've proposed here to
> keep things simple was to ensure -UKERNEL is passed and then only
> include files we know will work.
> 
> Refer to the patch "kprobes: port .kprobes.text to section range"
> in this series for an extension of the scripts/mod/modpost.c kernel
> headers use.

I think the rule of separating code is stricter for tools/ than it is
for scripts/.  The scripts are generally kernel-specific whereas the
tools are independent.  I believe the goal is to be able to copy them
out of the kernel tree and still be able to compile them.

> > As far as I can tell, the section name will always be
> > ".data.tbl.__jump_table.any".  Is that true?  If so, any reason why we
> > can't just hard-code the string here?
> 
> Its a fair strategy, however if upstream changes the order name we'd
> have to hand code this as well, by using a macro we keep it all in one
> place.

Hm, do you expect the section name to change often?

> > As you saw, if the string
> > changes, objtool will complain and 0-day will report it.
> 
> Indeed, which is why I was hoping to instead stick to a standard
> sections set of header files that lets us get these in on place.

Actually, I meant that obtool reporting the change would be a good
thing, in favor of just hard-coding the string.  It lets objtool do its
job of letting us know when something changes, like it did today.

> The only place I hand coded in this series was in the perl
> file scripts/recordmcount.pl but I suppose if we wanted to get
> creative we could even generate a header for it too.
> 
> If we want to avoid all this hacker include stuff another option
> is to *generate* each respective sections.h for the kernel, and
> also, one for tools, and one for perl. What do you think?

If the generated files aren't checked into git, tools/ will rely on
kernel files and will no longer be independent.  If they *are* checked
in, then we have to keep the files in sync.  Either way it sounds like
overkill, just to avoid hard-coding a string for which objtool will
already warn if it changes.

-- 
Josh

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 10/13] jump_label: port __jump_table to linker tables
@ 2016-07-22 22:55         ` Josh Poimboeuf
  0 siblings, 0 replies; 176+ messages in thread
From: Josh Poimboeuf @ 2016-07-22 22:55 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6, x86, luto, keescook, torvalds, gregkh, rusty, gnomes,
	alan, dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt

On Sat, Jul 23, 2016 at 12:26:54AM +0200, Luis R. Rodriguez wrote:
> On Fri, Jul 22, 2016 at 04:49:45PM -0500, Josh Poimboeuf wrote:
> > On Fri, Jul 22, 2016 at 02:24:44PM -0700, Luis R. Rodriguez wrote:
> > > diff --git a/tools/objtool/special.c b/tools/objtool/special.c
> > > index bff8abb3a4aa..f0ad369f994b 100644
> > > --- a/tools/objtool/special.c
> > > +++ b/tools/objtool/special.c
> > > @@ -26,6 +26,10 @@
> > >  #include "special.h"
> > >  #include "warn.h"
> > >  
> > > +#include "../../include/asm-generic/sections.h"
> > > +#include "../../include/asm-generic/tables.h"
> > > +#include "../../include/linux/stringify.h"
> > > +
> > >  #define EX_ENTRY_SIZE		12
> > >  #define EX_ORIG_OFFSET		0
> > >  #define EX_NEW_OFFSET		4
> > > @@ -63,7 +67,9 @@ struct special_entry entries[] = {
> > >  		.feature = ALT_FEATURE_OFFSET,
> > >  	},
> > >  	{
> > > -		.sec = "__jump_table",
> > > +		.sec = __stringify(SECTION_TBL(SECTION_DATA,
> > > +				               __jump_table,
> > > +					       SECTION_ORDER_ANY)),
> > >  		.jump_or_nop = true,
> > >  		.size = JUMP_ENTRY_SIZE,
> > >  		.orig = JUMP_ORIG_OFFSET,
> > 
> > (continuing our discussion from another thread...)
> > 
> > I think tools code isn't allowed to include kernel files because the
> > tools subdirectory is supposed to be completely independent.
> 
> That was also the case for userpsace tools in scripts/ -- for instance
> scripts/mod/modpost.c made an exception. What I've proposed here to
> keep things simple was to ensure -UKERNEL is passed and then only
> include files we know will work.
> 
> Refer to the patch "kprobes: port .kprobes.text to section range"
> in this series for an extension of the scripts/mod/modpost.c kernel
> headers use.

I think the rule of separating code is stricter for tools/ than it is
for scripts/.  The scripts are generally kernel-specific whereas the
tools are independent.  I believe the goal is to be able to copy them
out of the kernel tree and still be able to compile them.

> > As far as I can tell, the section name will always be
> > ".data.tbl.__jump_table.any".  Is that true?  If so, any reason why we
> > can't just hard-code the string here?
> 
> Its a fair strategy, however if upstream changes the order name we'd
> have to hand code this as well, by using a macro we keep it all in one
> place.

Hm, do you expect the section name to change often?

> > As you saw, if the string
> > changes, objtool will complain and 0-day will report it.
> 
> Indeed, which is why I was hoping to instead stick to a standard
> sections set of header files that lets us get these in on place.

Actually, I meant that obtool reporting the change would be a good
thing, in favor of just hard-coding the string.  It lets objtool do its
job of letting us know when something changes, like it did today.

> The only place I hand coded in this series was in the perl
> file scripts/recordmcount.pl but I suppose if we wanted to get
> creative we could even generate a header for it too.
> 
> If we want to avoid all this hacker include stuff another option
> is to *generate* each respective sections.h for the kernel, and
> also, one for tools, and one for perl. What do you think?

If the generated files aren't checked into git, tools/ will rely on
kernel files and will no longer be independent.  If they *are* checked
in, then we have to keep the files in sync.  Either way it sounds like
overkill, just to avoid hard-coding a string for which objtool will
already warn if it changes.

-- 
Josh

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
  2016-07-22 21:24 ` Luis R. Rodriguez
  (?)
@ 2016-07-25 13:32   ` Masami Hiramatsu
  -1 siblings, 0 replies; 176+ messages in thread
From: Masami Hiramatsu @ 2016-07-25 13:32 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel

Hi Luis,

On Fri, 22 Jul 2016 14:24:34 -0700
"Luis R. Rodriguez" <mcgrof@kernel.org> wrote:

> This RFC v3 builds off the last RFC v2 series [0] for adding linker tables.
> The largest amount of work here was to take Russell King's feedback on
> using linker table for kprobes text not being appropriate -- and providing
> another lightweight API for simple section ranges: read-only stitched pieces
> of executable code. This required also generalizing common building blocks
> for both linker tables and section ranges, these building blocks are defined
> now in include/linux/sections.h and asm-generic/section.h. The other last thing
> decided was to not support sub-sections. In the hunt for this I could think of
> anything that really required this, and if it was needed it did not seem
> impossible to port over to avoid its use. Please let me know if there are valid
> uses cases for sub-sections.
> 
> Other significant effort here was to provide a set of common assembly helpers
> which could be used across architectures, this starts off some of this work
> for generic helpers which carve out and define custom Linux sections.
> 
> Lastly, this now also goes with two ports which required module support when
> using linker tables: jump labels, and dynamic debug support. A few
> extensions have been made to the original series in order to provide
> support for that.
> 
> Since kprobes actually had both a linker table and a section range the
> patch that dealt with kprobes is now split off in two patches, one
> that deals with its linker table and another for its section ranges.
> 
> More elaborate uses for linker tables are possible, I'll hold off on any
> of this type of work until at least the basic building blocks are fleshed
> out. To review how this work came about, and more elaborate uses being
> evaluated check out the userspace linker-tables mockup solution [1].
> Hopefully most of the possible bikeshedding was already dealt with through
> that tree. Thanks to hpa for tons of feedback.

Great! so table and ranges completely replace the old-style(add-hoc)
_kprobe and NOKPROBE_SYMBOL() implementation, good job! :)

> 
> Should you need it, the code here is also available on my linux-next
> 20160722-linker-table-v3-try2 branch on kernel.org [2]. Lastly, ranges and
> table development go under copyleft-next, Rusty recently asked for code
> to go in prior to the license tag being added denoting this license as
> GPL-compatible [3] -- I had noted in the patch submission which annotated
> copyleft-next's compatibility to GPLv2 that copyleft-next is the license
> of choice for ongoing kernel development on my end [4]. If this is
> objectionable I'm happy to change it to GPLv2 however I'd like a reason
> provided as I've gone through all possible channels to ensure this is kosher,
> including vetting by 3 attorneys now, 2 at SUSE.

I'm not a lawyer, so I don't know really it is compatible with GPLv2,
and if it is, I'm not sure the reason why we need another license.
AFAICS the license terms, most of parts looks reasonable. I just concern
clause 8, after fifteen years, is that still GPLv2 compatible?
(I'd like see FAQ about this license...)

Thank you!

> 
> This all goes tested by 0-day... however since I found an issue with linker
> tables and blackfin this series remains as RFC -- I'll try to debug the
> issue with Steven Miao. The issue with blackfin is using a config that
> enables CONFIG_FW_LOADER=y and CONFIG_DYNAMIC_DEBUG=y [5] we end up with
> the following at final link time:
> 
>   LD      init/built-in.o
> lib/built-in.o: In function `dynamic_debug_init':
> lib/dynamic_debug.c:(.init.text+0x156): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x15a): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x160): undefined reference to `__verbose'
> lib/dynamic_debug.c:(.init.text+0x164): undefined reference to `__verbose'
> lib/dynamic_debug.c:(.init.text+0x214): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x218): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x252): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x258): undefined reference to `__verbose'
> lib/dynamic_debug.c:(.init.text+0x25c): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x260): undefined reference to `__verbose'
> drivers/built-in.o: In function `release_firmware':
> (.text+0x22dc2): undefined reference to `builtin_fw'
> drivers/built-in.o: In function `release_firmware':
> (.text+0x22dc6): undefined reference to `builtin_fw__end'
> drivers/built-in.o: In function `release_firmware':
> (.text+0x22dca): undefined reference to `builtin_fw'
> drivers/built-in.o: In function `release_firmware':
> (.text+0x22dce): undefined reference to `builtin_fw__end'
> drivers/built-in.o: In function `fw_get_builtin_firmware':
> drivers/base/firmware_class.c:(.text+0x23008): undefined reference to `builtin_fw'
> drivers/base/firmware_class.c:(.text+0x2300c): undefined reference to `builtin_fw__end'
> drivers/base/firmware_class.c:(.text+0x23010): undefined reference to `builtin_fw'
> drivers/base/firmware_class.c:(.text+0x23014): undefined reference to `builtin_fw__end'
> Makefile:957: recipe for target 'vmlinux' failed
> make: *** [vmlinux] Error 1
> 
> To reproduce then:
> 
> wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
> chmod +x ~/bin/make.cross
> wget http://drvbp1.linux-foundation.org/~mcgrof/2016/07/22/blackfin-fw-dyndbg.config -o .config
> make.cross ARCH=blackfin
> 
> [0] https://lkml.kernel.org/r/1455889559-9428-1-git-send-email-mcgrof@kernel.org
> [1] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linker-tables.git/
> [2] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linux-next.git/log/?h 160722-linker-table-v3-try2
> [3] https://lkml.kernel.org/r/87y44zhbiu.fsf@rustcorp.com.au
> [4] https://lkml.kernel.org/r/1467327207-14916-1-git-send-email-mcgrof@kernel.org
> [5] http://drvbp1.linux-foundation.org/~mcgrof/2016/07/22/blackfin-fw-dyndbg.config
> 
> 
> Luis R. Rodriguez (13):
>   x86: remove LTO_REFERENCE_INITCALL()
>   dell-smo8800: include uaccess.h
>   scripts/module-common.lds: enable generation
>   sections.h: guard against asm and linker script
>   sections.h: add sections header to collect all section info
>   ranges.h: add helpers to build and identify Linux section ranges
>   tables.h: add linker table support
>   firmware/Makefile: force recompilation if makefile changes
>   firmware: port built-in section to linker table
>   jump_label: port __jump_table to linker tables
>   dynamic_debug: port to use linker tables
>   kprobes: port .kprobes.text to section range
>   kprobes: port blacklist kprobes to linker table
> 
>  .gitignore                                         |   2 +
>  Documentation/DocBook/Makefile                     |   3 +-
>  Documentation/DocBook/linker-tables.tmpl           | 166 ++++++
>  Documentation/DocBook/sections.tmpl                | 112 ++++
>  Documentation/kbuild/makefiles.txt                 |  19 +
>  Makefile                                           |   6 +-
>  arch/alpha/include/asm/ranges.h                    |   6 +
>  arch/alpha/include/asm/sections.h                  |   6 +
>  arch/alpha/include/asm/tables.h                    |   6 +
>  arch/arc/include/asm/ranges.h                      |   6 +
>  arch/arc/include/asm/tables.h                      |   6 +
>  arch/arc/kernel/vmlinux.lds.S                      |   1 -
>  arch/arm/include/asm/jump_label.h                  |   6 +-
>  arch/arm/include/asm/ranges.h                      |   6 +
>  arch/arm/include/asm/sections.h                    |   2 +
>  arch/arm/include/asm/tables.h                      |   6 +
>  arch/arm/kernel/entry-armv.S                       |   3 +-
>  arch/arm/kernel/vmlinux-xip.lds.S                  |   1 -
>  arch/arm/kernel/vmlinux.lds.S                      |   1 -
>  arch/arm64/include/asm/jump_label.h                |   6 +-
>  arch/arm64/include/asm/ranges.h                    |   6 +
>  arch/arm64/include/asm/sections.h                  |   6 +
>  arch/arm64/include/asm/tables.h                    |   6 +
>  arch/avr32/include/asm/ranges.h                    |   6 +
>  arch/avr32/include/asm/sections.h                  |   6 +
>  arch/avr32/include/asm/tables.h                    |   6 +
>  arch/avr32/kernel/entry-avr32b.S                   |   5 +-
>  arch/avr32/kernel/vmlinux.lds.S                    |   1 -
>  arch/blackfin/include/asm/ranges.h                 |   6 +
>  arch/blackfin/include/asm/sections.h               |   4 +
>  arch/blackfin/include/asm/tables.h                 |   6 +
>  arch/blackfin/kernel/vmlinux.lds.S                 |   1 -
>  arch/c6x/include/asm/ranges.h                      |   6 +
>  arch/c6x/include/asm/tables.h                      |   6 +
>  arch/c6x/kernel/vmlinux.lds.S                      |   1 -
>  arch/cris/include/asm/ranges.h                     |   6 +
>  arch/cris/include/asm/sections.h                   |   6 +
>  arch/cris/include/asm/tables.h                     |   6 +
>  arch/frv/include/asm/ranges.h                      |   6 +
>  arch/frv/include/asm/tables.h                      |   6 +
>  arch/h8300/include/asm/ranges.h                    |   6 +
>  arch/h8300/include/asm/sections.h                  |   6 +
>  arch/h8300/include/asm/tables.h                    |   6 +
>  arch/hexagon/include/asm/ranges.h                  |   6 +
>  arch/hexagon/include/asm/sections.h                |   6 +
>  arch/hexagon/include/asm/tables.h                  |   6 +
>  arch/hexagon/kernel/vmlinux.lds.S                  |   1 -
>  arch/ia64/include/asm/ranges.h                     |   6 +
>  arch/ia64/include/asm/sections.h                   |   7 +-
>  arch/ia64/include/asm/tables.h                     |   6 +
>  arch/ia64/kernel/jprobes.S                         |   3 +-
>  arch/ia64/kernel/vmlinux.lds.S                     |   1 -
>  arch/ia64/lib/flush.S                              |   5 +-
>  arch/m32r/include/asm/ranges.h                     |   6 +
>  arch/m32r/include/asm/sections.h                   |   6 +
>  arch/m32r/include/asm/tables.h                     |   6 +
>  arch/m68k/include/asm/ranges.h                     |   6 +
>  arch/m68k/include/asm/sections.h                   |   6 +
>  arch/m68k/include/asm/tables.h                     |   6 +
>  arch/metag/include/asm/ranges.h                    |   6 +
>  arch/metag/include/asm/sections.h                  |   6 +
>  arch/metag/include/asm/tables.h                    |   6 +
>  arch/metag/kernel/vmlinux.lds.S                    |   1 -
>  arch/microblaze/include/asm/ranges.h               |   6 +
>  arch/microblaze/include/asm/tables.h               |   6 +
>  arch/microblaze/kernel/vmlinux.lds.S               |   1 -
>  arch/mips/include/asm/jump_label.h                 |   6 +-
>  arch/mips/include/asm/ranges.h                     |   6 +
>  arch/mips/include/asm/sections.h                   |   6 +
>  arch/mips/include/asm/tables.h                     |   6 +
>  arch/mips/kernel/vmlinux.lds.S                     |   1 -
>  arch/mn10300/include/asm/ranges.h                  |   6 +
>  arch/mn10300/include/asm/sections.h                |   6 +
>  arch/mn10300/include/asm/tables.h                  |   6 +
>  arch/mn10300/kernel/vmlinux.lds.S                  |   1 -
>  arch/nios2/include/asm/ranges.h                    |   6 +
>  arch/nios2/include/asm/sections.h                  |   6 +
>  arch/nios2/include/asm/tables.h                    |   6 +
>  arch/nios2/kernel/vmlinux.lds.S                    |   1 -
>  arch/openrisc/include/asm/ranges.h                 |   6 +
>  arch/openrisc/include/asm/sections.h               |   6 +
>  arch/openrisc/include/asm/tables.h                 |   6 +
>  arch/openrisc/kernel/vmlinux.lds.S                 |   1 -
>  arch/parisc/include/asm/ranges.h                   |   6 +
>  arch/parisc/include/asm/tables.h                   |   6 +
>  arch/parisc/kernel/vmlinux.lds.S                   |   1 -
>  arch/powerpc/include/asm/jump_label.h              |   8 +-
>  arch/powerpc/include/asm/ppc_asm.h                 |   7 +-
>  arch/powerpc/include/asm/ranges.h                  |   6 +
>  arch/powerpc/include/asm/sections.h                |  11 +-
>  arch/powerpc/include/asm/tables.h                  |   6 +
>  arch/powerpc/kernel/vmlinux.lds.S                  |   1 -
>  arch/s390/include/asm/jump_label.h                 |   6 +-
>  arch/s390/include/asm/ranges.h                     |   6 +
>  arch/s390/include/asm/tables.h                     |   6 +
>  arch/s390/kernel/entry.S                           |   5 +-
>  arch/s390/kernel/kprobes.c                         |   6 +-
>  arch/s390/kernel/mcount.S                          |   2 +-
>  arch/s390/kernel/vmlinux.lds.S                     |   1 -
>  arch/score/include/asm/ranges.h                    |   6 +
>  arch/score/include/asm/sections.h                  |   6 +
>  arch/score/include/asm/tables.h                    |   6 +
>  arch/score/kernel/vmlinux.lds.S                    |   1 -
>  arch/sh/include/asm/ranges.h                       |   6 +
>  arch/sh/include/asm/sections.h                     |   2 +
>  arch/sh/include/asm/tables.h                       |   6 +
>  arch/sh/kernel/vmlinux.lds.S                       |   1 -
>  arch/sparc/include/asm/jump_label.h                |   6 +-
>  arch/sparc/include/asm/ranges.h                    |   6 +
>  arch/sparc/include/asm/sections.h                  |   4 +
>  arch/sparc/include/asm/tables.h                    |   6 +
>  arch/sparc/kernel/vmlinux.lds.S                    |   1 -
>  arch/sparc/mm/ultra.S                              |   3 +-
>  arch/tile/include/asm/ranges.h                     |   6 +
>  arch/tile/include/asm/sections.h                   |   4 +
>  arch/tile/include/asm/tables.h                     |   6 +
>  arch/tile/kernel/vmlinux.lds.S                     |   1 -
>  arch/um/include/asm/ranges.h                       |   6 +
>  arch/um/include/asm/tables.h                       |   6 +
>  arch/unicore32/include/asm/ranges.h                |   6 +
>  arch/unicore32/include/asm/sections.h              |   6 +
>  arch/unicore32/include/asm/tables.h                |   6 +
>  arch/x86/include/asm/jump_label.h                  |  10 +-
>  arch/x86/include/asm/ranges.h                      |   6 +
>  arch/x86/include/asm/sections.h                    |  23 +-
>  arch/x86/include/asm/tables.h                      |   6 +
>  arch/x86/include/asm/uaccess.h                     |  18 +-
>  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                            |   3 +
>  arch/xtensa/include/asm/ranges.h                   |   6 +
>  arch/xtensa/include/asm/sections.h                 |   6 +
>  arch/xtensa/include/asm/tables.h                   |   6 +
>  drivers/base/firmware_class.c                      |  12 +-
>  drivers/platform/x86/dell-smo8800.c                |   1 +
>  firmware/Makefile                                  |   7 +-
>  include/asm-generic/ranges.h                       |  70 +++
>  include/asm-generic/sections.h                     | 306 ++++++++++-
>  include/asm-generic/tables.h                       |  70 +++
>  include/asm-generic/vmlinux.lds.h                  |  66 +--
>  include/linux/compiler.h                           |   2 +-
>  include/linux/dynamic_debug.h                      |   5 +-
>  include/linux/init.h                               |  20 +-
>  include/linux/jump_label.h                         |  10 +-
>  include/linux/kprobes.h                            |   8 +-
>  include/linux/ranges.h                             |  54 ++
>  include/linux/sections.h                           | 123 +++++
>  include/linux/tables.h                             | 597 +++++++++++++++++++++
>  kernel/jump_label.c                                |  17 +-
>  kernel/kprobes.c                                   |  17 +-
>  lib/dynamic_debug.c                                |  13 +-
>  scripts/Makefile                                   |   1 +
>  scripts/Makefile.build                             |   4 +-
>  scripts/Makefile.clean                             |   1 +
>  scripts/Makefile.lib                               |  12 +
>  scripts/Makefile.modpost                           |   2 +-
>  scripts/mod/Makefile                               |   2 +
>  scripts/mod/modpost.c                              |   8 +-
>  scripts/{module-common.lds => module-common.lds.S} |   6 +
>  scripts/recordmcount.c                             |   7 +-
>  scripts/recordmcount.pl                            |   2 +-
>  tools/include/linux/sections.h                     |  13 +
>  tools/objtool/special.c                            |   8 +-
>  164 files changed, 2241 insertions(+), 205 deletions(-)
>  create mode 100644 Documentation/DocBook/linker-tables.tmpl
>  create mode 100644 Documentation/DocBook/sections.tmpl
>  create mode 100644 arch/alpha/include/asm/ranges.h
>  create mode 100644 arch/alpha/include/asm/sections.h
>  create mode 100644 arch/alpha/include/asm/tables.h
>  create mode 100644 arch/arc/include/asm/ranges.h
>  create mode 100644 arch/arc/include/asm/tables.h
>  create mode 100644 arch/arm/include/asm/ranges.h
>  create mode 100644 arch/arm/include/asm/tables.h
>  create mode 100644 arch/arm64/include/asm/ranges.h
>  create mode 100644 arch/arm64/include/asm/sections.h
>  create mode 100644 arch/arm64/include/asm/tables.h
>  create mode 100644 arch/avr32/include/asm/ranges.h
>  create mode 100644 arch/avr32/include/asm/sections.h
>  create mode 100644 arch/avr32/include/asm/tables.h
>  create mode 100644 arch/blackfin/include/asm/ranges.h
>  create mode 100644 arch/blackfin/include/asm/tables.h
>  create mode 100644 arch/c6x/include/asm/ranges.h
>  create mode 100644 arch/c6x/include/asm/tables.h
>  create mode 100644 arch/cris/include/asm/ranges.h
>  create mode 100644 arch/cris/include/asm/sections.h
>  create mode 100644 arch/cris/include/asm/tables.h
>  create mode 100644 arch/frv/include/asm/ranges.h
>  create mode 100644 arch/frv/include/asm/tables.h
>  create mode 100644 arch/h8300/include/asm/ranges.h
>  create mode 100644 arch/h8300/include/asm/sections.h
>  create mode 100644 arch/h8300/include/asm/tables.h
>  create mode 100644 arch/hexagon/include/asm/ranges.h
>  create mode 100644 arch/hexagon/include/asm/sections.h
>  create mode 100644 arch/hexagon/include/asm/tables.h
>  create mode 100644 arch/ia64/include/asm/ranges.h
>  create mode 100644 arch/ia64/include/asm/tables.h
>  create mode 100644 arch/m32r/include/asm/ranges.h
>  create mode 100644 arch/m32r/include/asm/sections.h
>  create mode 100644 arch/m32r/include/asm/tables.h
>  create mode 100644 arch/m68k/include/asm/ranges.h
>  create mode 100644 arch/m68k/include/asm/sections.h
>  create mode 100644 arch/m68k/include/asm/tables.h
>  create mode 100644 arch/metag/include/asm/ranges.h
>  create mode 100644 arch/metag/include/asm/sections.h
>  create mode 100644 arch/metag/include/asm/tables.h
>  create mode 100644 arch/microblaze/include/asm/ranges.h
>  create mode 100644 arch/microblaze/include/asm/tables.h
>  create mode 100644 arch/mips/include/asm/ranges.h
>  create mode 100644 arch/mips/include/asm/sections.h
>  create mode 100644 arch/mips/include/asm/tables.h
>  create mode 100644 arch/mn10300/include/asm/ranges.h
>  create mode 100644 arch/mn10300/include/asm/sections.h
>  create mode 100644 arch/mn10300/include/asm/tables.h
>  create mode 100644 arch/nios2/include/asm/ranges.h
>  create mode 100644 arch/nios2/include/asm/sections.h
>  create mode 100644 arch/nios2/include/asm/tables.h
>  create mode 100644 arch/openrisc/include/asm/ranges.h
>  create mode 100644 arch/openrisc/include/asm/sections.h
>  create mode 100644 arch/openrisc/include/asm/tables.h
>  create mode 100644 arch/parisc/include/asm/ranges.h
>  create mode 100644 arch/parisc/include/asm/tables.h
>  create mode 100644 arch/powerpc/include/asm/ranges.h
>  create mode 100644 arch/powerpc/include/asm/tables.h
>  create mode 100644 arch/s390/include/asm/ranges.h
>  create mode 100644 arch/s390/include/asm/tables.h
>  create mode 100644 arch/score/include/asm/ranges.h
>  create mode 100644 arch/score/include/asm/sections.h
>  create mode 100644 arch/score/include/asm/tables.h
>  create mode 100644 arch/sh/include/asm/ranges.h
>  create mode 100644 arch/sh/include/asm/tables.h
>  create mode 100644 arch/sparc/include/asm/ranges.h
>  create mode 100644 arch/sparc/include/asm/tables.h
>  create mode 100644 arch/tile/include/asm/ranges.h
>  create mode 100644 arch/tile/include/asm/tables.h
>  create mode 100644 arch/um/include/asm/ranges.h
>  create mode 100644 arch/um/include/asm/tables.h
>  create mode 100644 arch/unicore32/include/asm/ranges.h
>  create mode 100644 arch/unicore32/include/asm/sections.h
>  create mode 100644 arch/unicore32/include/asm/tables.h
>  create mode 100644 arch/x86/include/asm/ranges.h
>  create mode 100644 arch/x86/include/asm/tables.h
>  create mode 100644 arch/xtensa/include/asm/ranges.h
>  create mode 100644 arch/xtensa/include/asm/sections.h
>  create mode 100644 arch/xtensa/include/asm/tables.h
>  create mode 100644 include/asm-generic/ranges.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%)
>  create mode 100644 tools/include/linux/sections.h
> 
> -- 
> 2.8.4
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-07-25 13:32   ` Masami Hiramatsu
  0 siblings, 0 replies; 176+ messages in thread
From: Masami Hiramatsu @ 2016-07-25 13:32 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel

Hi Luis,

On Fri, 22 Jul 2016 14:24:34 -0700
"Luis R. Rodriguez" <mcgrof@kernel.org> wrote:

> This RFC v3 builds off the last RFC v2 series [0] for adding linker tables.
> The largest amount of work here was to take Russell King's feedback on
> using linker table for kprobes text not being appropriate -- and providing
> another lightweight API for simple section ranges: read-only stitched pieces
> of executable code. This required also generalizing common building blocks
> for both linker tables and section ranges, these building blocks are defined
> now in include/linux/sections.h and asm-generic/section.h. The other last thing
> decided was to not support sub-sections. In the hunt for this I could think of
> anything that really required this, and if it was needed it did not seem
> impossible to port over to avoid its use. Please let me know if there are valid
> uses cases for sub-sections.
> 
> Other significant effort here was to provide a set of common assembly helpers
> which could be used across architectures, this starts off some of this work
> for generic helpers which carve out and define custom Linux sections.
> 
> Lastly, this now also goes with two ports which required module support when
> using linker tables: jump labels, and dynamic debug support. A few
> extensions have been made to the original series in order to provide
> support for that.
> 
> Since kprobes actually had both a linker table and a section range the
> patch that dealt with kprobes is now split off in two patches, one
> that deals with its linker table and another for its section ranges.
> 
> More elaborate uses for linker tables are possible, I'll hold off on any
> of this type of work until at least the basic building blocks are fleshed
> out. To review how this work came about, and more elaborate uses being
> evaluated check out the userspace linker-tables mockup solution [1].
> Hopefully most of the possible bikeshedding was already dealt with through
> that tree. Thanks to hpa for tons of feedback.

Great! so table and ranges completely replace the old-style(add-hoc)
_kprobe and NOKPROBE_SYMBOL() implementation, good job! :)

> 
> Should you need it, the code here is also available on my linux-next
> 20160722-linker-table-v3-try2 branch on kernel.org [2]. Lastly, ranges and
> table development go under copyleft-next, Rusty recently asked for code
> to go in prior to the license tag being added denoting this license as
> GPL-compatible [3] -- I had noted in the patch submission which annotated
> copyleft-next's compatibility to GPLv2 that copyleft-next is the license
> of choice for ongoing kernel development on my end [4]. If this is
> objectionable I'm happy to change it to GPLv2 however I'd like a reason
> provided as I've gone through all possible channels to ensure this is kosher,
> including vetting by 3 attorneys now, 2 at SUSE.

I'm not a lawyer, so I don't know really it is compatible with GPLv2,
and if it is, I'm not sure the reason why we need another license.
AFAICS the license terms, most of parts looks reasonable. I just concern
clause 8, after fifteen years, is that still GPLv2 compatible?
(I'd like see FAQ about this license...)

Thank you!

> 
> This all goes tested by 0-day... however since I found an issue with linker
> tables and blackfin this series remains as RFC -- I'll try to debug the
> issue with Steven Miao. The issue with blackfin is using a config that
> enables CONFIG_FW_LOADER=y and CONFIG_DYNAMIC_DEBUG=y [5] we end up with
> the following at final link time:
> 
>   LD      init/built-in.o
> lib/built-in.o: In function `dynamic_debug_init':
> lib/dynamic_debug.c:(.init.text+0x156): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x15a): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x160): undefined reference to `__verbose'
> lib/dynamic_debug.c:(.init.text+0x164): undefined reference to `__verbose'
> lib/dynamic_debug.c:(.init.text+0x214): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x218): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x252): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x258): undefined reference to `__verbose'
> lib/dynamic_debug.c:(.init.text+0x25c): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x260): undefined reference to `__verbose'
> drivers/built-in.o: In function `release_firmware':
> (.text+0x22dc2): undefined reference to `builtin_fw'
> drivers/built-in.o: In function `release_firmware':
> (.text+0x22dc6): undefined reference to `builtin_fw__end'
> drivers/built-in.o: In function `release_firmware':
> (.text+0x22dca): undefined reference to `builtin_fw'
> drivers/built-in.o: In function `release_firmware':
> (.text+0x22dce): undefined reference to `builtin_fw__end'
> drivers/built-in.o: In function `fw_get_builtin_firmware':
> drivers/base/firmware_class.c:(.text+0x23008): undefined reference to `builtin_fw'
> drivers/base/firmware_class.c:(.text+0x2300c): undefined reference to `builtin_fw__end'
> drivers/base/firmware_class.c:(.text+0x23010): undefined reference to `builtin_fw'
> drivers/base/firmware_class.c:(.text+0x23014): undefined reference to `builtin_fw__end'
> Makefile:957: recipe for target 'vmlinux' failed
> make: *** [vmlinux] Error 1
> 
> To reproduce then:
> 
> wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
> chmod +x ~/bin/make.cross
> wget http://drvbp1.linux-foundation.org/~mcgrof/2016/07/22/blackfin-fw-dyndbg.config -o .config
> make.cross ARCH=blackfin
> 
> [0] https://lkml.kernel.org/r/1455889559-9428-1-git-send-email-mcgrof@kernel.org
> [1] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linker-tables.git/
> [2] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linux-next.git/log/?h=20160722-linker-table-v3-try2
> [3] https://lkml.kernel.org/r/87y44zhbiu.fsf@rustcorp.com.au
> [4] https://lkml.kernel.org/r/1467327207-14916-1-git-send-email-mcgrof@kernel.org
> [5] http://drvbp1.linux-foundation.org/~mcgrof/2016/07/22/blackfin-fw-dyndbg.config
> 
> 
> Luis R. Rodriguez (13):
>   x86: remove LTO_REFERENCE_INITCALL()
>   dell-smo8800: include uaccess.h
>   scripts/module-common.lds: enable generation
>   sections.h: guard against asm and linker script
>   sections.h: add sections header to collect all section info
>   ranges.h: add helpers to build and identify Linux section ranges
>   tables.h: add linker table support
>   firmware/Makefile: force recompilation if makefile changes
>   firmware: port built-in section to linker table
>   jump_label: port __jump_table to linker tables
>   dynamic_debug: port to use linker tables
>   kprobes: port .kprobes.text to section range
>   kprobes: port blacklist kprobes to linker table
> 
>  .gitignore                                         |   2 +
>  Documentation/DocBook/Makefile                     |   3 +-
>  Documentation/DocBook/linker-tables.tmpl           | 166 ++++++
>  Documentation/DocBook/sections.tmpl                | 112 ++++
>  Documentation/kbuild/makefiles.txt                 |  19 +
>  Makefile                                           |   6 +-
>  arch/alpha/include/asm/ranges.h                    |   6 +
>  arch/alpha/include/asm/sections.h                  |   6 +
>  arch/alpha/include/asm/tables.h                    |   6 +
>  arch/arc/include/asm/ranges.h                      |   6 +
>  arch/arc/include/asm/tables.h                      |   6 +
>  arch/arc/kernel/vmlinux.lds.S                      |   1 -
>  arch/arm/include/asm/jump_label.h                  |   6 +-
>  arch/arm/include/asm/ranges.h                      |   6 +
>  arch/arm/include/asm/sections.h                    |   2 +
>  arch/arm/include/asm/tables.h                      |   6 +
>  arch/arm/kernel/entry-armv.S                       |   3 +-
>  arch/arm/kernel/vmlinux-xip.lds.S                  |   1 -
>  arch/arm/kernel/vmlinux.lds.S                      |   1 -
>  arch/arm64/include/asm/jump_label.h                |   6 +-
>  arch/arm64/include/asm/ranges.h                    |   6 +
>  arch/arm64/include/asm/sections.h                  |   6 +
>  arch/arm64/include/asm/tables.h                    |   6 +
>  arch/avr32/include/asm/ranges.h                    |   6 +
>  arch/avr32/include/asm/sections.h                  |   6 +
>  arch/avr32/include/asm/tables.h                    |   6 +
>  arch/avr32/kernel/entry-avr32b.S                   |   5 +-
>  arch/avr32/kernel/vmlinux.lds.S                    |   1 -
>  arch/blackfin/include/asm/ranges.h                 |   6 +
>  arch/blackfin/include/asm/sections.h               |   4 +
>  arch/blackfin/include/asm/tables.h                 |   6 +
>  arch/blackfin/kernel/vmlinux.lds.S                 |   1 -
>  arch/c6x/include/asm/ranges.h                      |   6 +
>  arch/c6x/include/asm/tables.h                      |   6 +
>  arch/c6x/kernel/vmlinux.lds.S                      |   1 -
>  arch/cris/include/asm/ranges.h                     |   6 +
>  arch/cris/include/asm/sections.h                   |   6 +
>  arch/cris/include/asm/tables.h                     |   6 +
>  arch/frv/include/asm/ranges.h                      |   6 +
>  arch/frv/include/asm/tables.h                      |   6 +
>  arch/h8300/include/asm/ranges.h                    |   6 +
>  arch/h8300/include/asm/sections.h                  |   6 +
>  arch/h8300/include/asm/tables.h                    |   6 +
>  arch/hexagon/include/asm/ranges.h                  |   6 +
>  arch/hexagon/include/asm/sections.h                |   6 +
>  arch/hexagon/include/asm/tables.h                  |   6 +
>  arch/hexagon/kernel/vmlinux.lds.S                  |   1 -
>  arch/ia64/include/asm/ranges.h                     |   6 +
>  arch/ia64/include/asm/sections.h                   |   7 +-
>  arch/ia64/include/asm/tables.h                     |   6 +
>  arch/ia64/kernel/jprobes.S                         |   3 +-
>  arch/ia64/kernel/vmlinux.lds.S                     |   1 -
>  arch/ia64/lib/flush.S                              |   5 +-
>  arch/m32r/include/asm/ranges.h                     |   6 +
>  arch/m32r/include/asm/sections.h                   |   6 +
>  arch/m32r/include/asm/tables.h                     |   6 +
>  arch/m68k/include/asm/ranges.h                     |   6 +
>  arch/m68k/include/asm/sections.h                   |   6 +
>  arch/m68k/include/asm/tables.h                     |   6 +
>  arch/metag/include/asm/ranges.h                    |   6 +
>  arch/metag/include/asm/sections.h                  |   6 +
>  arch/metag/include/asm/tables.h                    |   6 +
>  arch/metag/kernel/vmlinux.lds.S                    |   1 -
>  arch/microblaze/include/asm/ranges.h               |   6 +
>  arch/microblaze/include/asm/tables.h               |   6 +
>  arch/microblaze/kernel/vmlinux.lds.S               |   1 -
>  arch/mips/include/asm/jump_label.h                 |   6 +-
>  arch/mips/include/asm/ranges.h                     |   6 +
>  arch/mips/include/asm/sections.h                   |   6 +
>  arch/mips/include/asm/tables.h                     |   6 +
>  arch/mips/kernel/vmlinux.lds.S                     |   1 -
>  arch/mn10300/include/asm/ranges.h                  |   6 +
>  arch/mn10300/include/asm/sections.h                |   6 +
>  arch/mn10300/include/asm/tables.h                  |   6 +
>  arch/mn10300/kernel/vmlinux.lds.S                  |   1 -
>  arch/nios2/include/asm/ranges.h                    |   6 +
>  arch/nios2/include/asm/sections.h                  |   6 +
>  arch/nios2/include/asm/tables.h                    |   6 +
>  arch/nios2/kernel/vmlinux.lds.S                    |   1 -
>  arch/openrisc/include/asm/ranges.h                 |   6 +
>  arch/openrisc/include/asm/sections.h               |   6 +
>  arch/openrisc/include/asm/tables.h                 |   6 +
>  arch/openrisc/kernel/vmlinux.lds.S                 |   1 -
>  arch/parisc/include/asm/ranges.h                   |   6 +
>  arch/parisc/include/asm/tables.h                   |   6 +
>  arch/parisc/kernel/vmlinux.lds.S                   |   1 -
>  arch/powerpc/include/asm/jump_label.h              |   8 +-
>  arch/powerpc/include/asm/ppc_asm.h                 |   7 +-
>  arch/powerpc/include/asm/ranges.h                  |   6 +
>  arch/powerpc/include/asm/sections.h                |  11 +-
>  arch/powerpc/include/asm/tables.h                  |   6 +
>  arch/powerpc/kernel/vmlinux.lds.S                  |   1 -
>  arch/s390/include/asm/jump_label.h                 |   6 +-
>  arch/s390/include/asm/ranges.h                     |   6 +
>  arch/s390/include/asm/tables.h                     |   6 +
>  arch/s390/kernel/entry.S                           |   5 +-
>  arch/s390/kernel/kprobes.c                         |   6 +-
>  arch/s390/kernel/mcount.S                          |   2 +-
>  arch/s390/kernel/vmlinux.lds.S                     |   1 -
>  arch/score/include/asm/ranges.h                    |   6 +
>  arch/score/include/asm/sections.h                  |   6 +
>  arch/score/include/asm/tables.h                    |   6 +
>  arch/score/kernel/vmlinux.lds.S                    |   1 -
>  arch/sh/include/asm/ranges.h                       |   6 +
>  arch/sh/include/asm/sections.h                     |   2 +
>  arch/sh/include/asm/tables.h                       |   6 +
>  arch/sh/kernel/vmlinux.lds.S                       |   1 -
>  arch/sparc/include/asm/jump_label.h                |   6 +-
>  arch/sparc/include/asm/ranges.h                    |   6 +
>  arch/sparc/include/asm/sections.h                  |   4 +
>  arch/sparc/include/asm/tables.h                    |   6 +
>  arch/sparc/kernel/vmlinux.lds.S                    |   1 -
>  arch/sparc/mm/ultra.S                              |   3 +-
>  arch/tile/include/asm/ranges.h                     |   6 +
>  arch/tile/include/asm/sections.h                   |   4 +
>  arch/tile/include/asm/tables.h                     |   6 +
>  arch/tile/kernel/vmlinux.lds.S                     |   1 -
>  arch/um/include/asm/ranges.h                       |   6 +
>  arch/um/include/asm/tables.h                       |   6 +
>  arch/unicore32/include/asm/ranges.h                |   6 +
>  arch/unicore32/include/asm/sections.h              |   6 +
>  arch/unicore32/include/asm/tables.h                |   6 +
>  arch/x86/include/asm/jump_label.h                  |  10 +-
>  arch/x86/include/asm/ranges.h                      |   6 +
>  arch/x86/include/asm/sections.h                    |  23 +-
>  arch/x86/include/asm/tables.h                      |   6 +
>  arch/x86/include/asm/uaccess.h                     |  18 +-
>  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                            |   3 +
>  arch/xtensa/include/asm/ranges.h                   |   6 +
>  arch/xtensa/include/asm/sections.h                 |   6 +
>  arch/xtensa/include/asm/tables.h                   |   6 +
>  drivers/base/firmware_class.c                      |  12 +-
>  drivers/platform/x86/dell-smo8800.c                |   1 +
>  firmware/Makefile                                  |   7 +-
>  include/asm-generic/ranges.h                       |  70 +++
>  include/asm-generic/sections.h                     | 306 ++++++++++-
>  include/asm-generic/tables.h                       |  70 +++
>  include/asm-generic/vmlinux.lds.h                  |  66 +--
>  include/linux/compiler.h                           |   2 +-
>  include/linux/dynamic_debug.h                      |   5 +-
>  include/linux/init.h                               |  20 +-
>  include/linux/jump_label.h                         |  10 +-
>  include/linux/kprobes.h                            |   8 +-
>  include/linux/ranges.h                             |  54 ++
>  include/linux/sections.h                           | 123 +++++
>  include/linux/tables.h                             | 597 +++++++++++++++++++++
>  kernel/jump_label.c                                |  17 +-
>  kernel/kprobes.c                                   |  17 +-
>  lib/dynamic_debug.c                                |  13 +-
>  scripts/Makefile                                   |   1 +
>  scripts/Makefile.build                             |   4 +-
>  scripts/Makefile.clean                             |   1 +
>  scripts/Makefile.lib                               |  12 +
>  scripts/Makefile.modpost                           |   2 +-
>  scripts/mod/Makefile                               |   2 +
>  scripts/mod/modpost.c                              |   8 +-
>  scripts/{module-common.lds => module-common.lds.S} |   6 +
>  scripts/recordmcount.c                             |   7 +-
>  scripts/recordmcount.pl                            |   2 +-
>  tools/include/linux/sections.h                     |  13 +
>  tools/objtool/special.c                            |   8 +-
>  164 files changed, 2241 insertions(+), 205 deletions(-)
>  create mode 100644 Documentation/DocBook/linker-tables.tmpl
>  create mode 100644 Documentation/DocBook/sections.tmpl
>  create mode 100644 arch/alpha/include/asm/ranges.h
>  create mode 100644 arch/alpha/include/asm/sections.h
>  create mode 100644 arch/alpha/include/asm/tables.h
>  create mode 100644 arch/arc/include/asm/ranges.h
>  create mode 100644 arch/arc/include/asm/tables.h
>  create mode 100644 arch/arm/include/asm/ranges.h
>  create mode 100644 arch/arm/include/asm/tables.h
>  create mode 100644 arch/arm64/include/asm/ranges.h
>  create mode 100644 arch/arm64/include/asm/sections.h
>  create mode 100644 arch/arm64/include/asm/tables.h
>  create mode 100644 arch/avr32/include/asm/ranges.h
>  create mode 100644 arch/avr32/include/asm/sections.h
>  create mode 100644 arch/avr32/include/asm/tables.h
>  create mode 100644 arch/blackfin/include/asm/ranges.h
>  create mode 100644 arch/blackfin/include/asm/tables.h
>  create mode 100644 arch/c6x/include/asm/ranges.h
>  create mode 100644 arch/c6x/include/asm/tables.h
>  create mode 100644 arch/cris/include/asm/ranges.h
>  create mode 100644 arch/cris/include/asm/sections.h
>  create mode 100644 arch/cris/include/asm/tables.h
>  create mode 100644 arch/frv/include/asm/ranges.h
>  create mode 100644 arch/frv/include/asm/tables.h
>  create mode 100644 arch/h8300/include/asm/ranges.h
>  create mode 100644 arch/h8300/include/asm/sections.h
>  create mode 100644 arch/h8300/include/asm/tables.h
>  create mode 100644 arch/hexagon/include/asm/ranges.h
>  create mode 100644 arch/hexagon/include/asm/sections.h
>  create mode 100644 arch/hexagon/include/asm/tables.h
>  create mode 100644 arch/ia64/include/asm/ranges.h
>  create mode 100644 arch/ia64/include/asm/tables.h
>  create mode 100644 arch/m32r/include/asm/ranges.h
>  create mode 100644 arch/m32r/include/asm/sections.h
>  create mode 100644 arch/m32r/include/asm/tables.h
>  create mode 100644 arch/m68k/include/asm/ranges.h
>  create mode 100644 arch/m68k/include/asm/sections.h
>  create mode 100644 arch/m68k/include/asm/tables.h
>  create mode 100644 arch/metag/include/asm/ranges.h
>  create mode 100644 arch/metag/include/asm/sections.h
>  create mode 100644 arch/metag/include/asm/tables.h
>  create mode 100644 arch/microblaze/include/asm/ranges.h
>  create mode 100644 arch/microblaze/include/asm/tables.h
>  create mode 100644 arch/mips/include/asm/ranges.h
>  create mode 100644 arch/mips/include/asm/sections.h
>  create mode 100644 arch/mips/include/asm/tables.h
>  create mode 100644 arch/mn10300/include/asm/ranges.h
>  create mode 100644 arch/mn10300/include/asm/sections.h
>  create mode 100644 arch/mn10300/include/asm/tables.h
>  create mode 100644 arch/nios2/include/asm/ranges.h
>  create mode 100644 arch/nios2/include/asm/sections.h
>  create mode 100644 arch/nios2/include/asm/tables.h
>  create mode 100644 arch/openrisc/include/asm/ranges.h
>  create mode 100644 arch/openrisc/include/asm/sections.h
>  create mode 100644 arch/openrisc/include/asm/tables.h
>  create mode 100644 arch/parisc/include/asm/ranges.h
>  create mode 100644 arch/parisc/include/asm/tables.h
>  create mode 100644 arch/powerpc/include/asm/ranges.h
>  create mode 100644 arch/powerpc/include/asm/tables.h
>  create mode 100644 arch/s390/include/asm/ranges.h
>  create mode 100644 arch/s390/include/asm/tables.h
>  create mode 100644 arch/score/include/asm/ranges.h
>  create mode 100644 arch/score/include/asm/sections.h
>  create mode 100644 arch/score/include/asm/tables.h
>  create mode 100644 arch/sh/include/asm/ranges.h
>  create mode 100644 arch/sh/include/asm/tables.h
>  create mode 100644 arch/sparc/include/asm/ranges.h
>  create mode 100644 arch/sparc/include/asm/tables.h
>  create mode 100644 arch/tile/include/asm/ranges.h
>  create mode 100644 arch/tile/include/asm/tables.h
>  create mode 100644 arch/um/include/asm/ranges.h
>  create mode 100644 arch/um/include/asm/tables.h
>  create mode 100644 arch/unicore32/include/asm/ranges.h
>  create mode 100644 arch/unicore32/include/asm/sections.h
>  create mode 100644 arch/unicore32/include/asm/tables.h
>  create mode 100644 arch/x86/include/asm/ranges.h
>  create mode 100644 arch/x86/include/asm/tables.h
>  create mode 100644 arch/xtensa/include/asm/ranges.h
>  create mode 100644 arch/xtensa/include/asm/sections.h
>  create mode 100644 arch/xtensa/include/asm/tables.h
>  create mode 100644 include/asm-generic/ranges.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%)
>  create mode 100644 tools/include/linux/sections.h
> 
> -- 
> 2.8.4
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-07-25 13:32   ` Masami Hiramatsu
  0 siblings, 0 replies; 176+ messages in thread
From: Masami Hiramatsu @ 2016-07-25 13:32 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe

Hi Luis,

On Fri, 22 Jul 2016 14:24:34 -0700
"Luis R. Rodriguez" <mcgrof@kernel.org> wrote:

> This RFC v3 builds off the last RFC v2 series [0] for adding linker tables.
> The largest amount of work here was to take Russell King's feedback on
> using linker table for kprobes text not being appropriate -- and providing
> another lightweight API for simple section ranges: read-only stitched pieces
> of executable code. This required also generalizing common building blocks
> for both linker tables and section ranges, these building blocks are defined
> now in include/linux/sections.h and asm-generic/section.h. The other last thing
> decided was to not support sub-sections. In the hunt for this I could think of
> anything that really required this, and if it was needed it did not seem
> impossible to port over to avoid its use. Please let me know if there are valid
> uses cases for sub-sections.
> 
> Other significant effort here was to provide a set of common assembly helpers
> which could be used across architectures, this starts off some of this work
> for generic helpers which carve out and define custom Linux sections.
> 
> Lastly, this now also goes with two ports which required module support when
> using linker tables: jump labels, and dynamic debug support. A few
> extensions have been made to the original series in order to provide
> support for that.
> 
> Since kprobes actually had both a linker table and a section range the
> patch that dealt with kprobes is now split off in two patches, one
> that deals with its linker table and another for its section ranges.
> 
> More elaborate uses for linker tables are possible, I'll hold off on any
> of this type of work until at least the basic building blocks are fleshed
> out. To review how this work came about, and more elaborate uses being
> evaluated check out the userspace linker-tables mockup solution [1].
> Hopefully most of the possible bikeshedding was already dealt with through
> that tree. Thanks to hpa for tons of feedback.

Great! so table and ranges completely replace the old-style(add-hoc)
_kprobe and NOKPROBE_SYMBOL() implementation, good job! :)

> 
> Should you need it, the code here is also available on my linux-next
> 20160722-linker-table-v3-try2 branch on kernel.org [2]. Lastly, ranges and
> table development go under copyleft-next, Rusty recently asked for code
> to go in prior to the license tag being added denoting this license as
> GPL-compatible [3] -- I had noted in the patch submission which annotated
> copyleft-next's compatibility to GPLv2 that copyleft-next is the license
> of choice for ongoing kernel development on my end [4]. If this is
> objectionable I'm happy to change it to GPLv2 however I'd like a reason
> provided as I've gone through all possible channels to ensure this is kosher,
> including vetting by 3 attorneys now, 2 at SUSE.

I'm not a lawyer, so I don't know really it is compatible with GPLv2,
and if it is, I'm not sure the reason why we need another license.
AFAICS the license terms, most of parts looks reasonable. I just concern
clause 8, after fifteen years, is that still GPLv2 compatible?
(I'd like see FAQ about this license...)

Thank you!

> 
> This all goes tested by 0-day... however since I found an issue with linker
> tables and blackfin this series remains as RFC -- I'll try to debug the
> issue with Steven Miao. The issue with blackfin is using a config that
> enables CONFIG_FW_LOADER=y and CONFIG_DYNAMIC_DEBUG=y [5] we end up with
> the following at final link time:
> 
>   LD      init/built-in.o
> lib/built-in.o: In function `dynamic_debug_init':
> lib/dynamic_debug.c:(.init.text+0x156): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x15a): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x160): undefined reference to `__verbose'
> lib/dynamic_debug.c:(.init.text+0x164): undefined reference to `__verbose'
> lib/dynamic_debug.c:(.init.text+0x214): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x218): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x252): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x258): undefined reference to `__verbose'
> lib/dynamic_debug.c:(.init.text+0x25c): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x260): undefined reference to `__verbose'
> drivers/built-in.o: In function `release_firmware':
> (.text+0x22dc2): undefined reference to `builtin_fw'
> drivers/built-in.o: In function `release_firmware':
> (.text+0x22dc6): undefined reference to `builtin_fw__end'
> drivers/built-in.o: In function `release_firmware':
> (.text+0x22dca): undefined reference to `builtin_fw'
> drivers/built-in.o: In function `release_firmware':
> (.text+0x22dce): undefined reference to `builtin_fw__end'
> drivers/built-in.o: In function `fw_get_builtin_firmware':
> drivers/base/firmware_class.c:(.text+0x23008): undefined reference to `builtin_fw'
> drivers/base/firmware_class.c:(.text+0x2300c): undefined reference to `builtin_fw__end'
> drivers/base/firmware_class.c:(.text+0x23010): undefined reference to `builtin_fw'
> drivers/base/firmware_class.c:(.text+0x23014): undefined reference to `builtin_fw__end'
> Makefile:957: recipe for target 'vmlinux' failed
> make: *** [vmlinux] Error 1
> 
> To reproduce then:
> 
> wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
> chmod +x ~/bin/make.cross
> wget http://drvbp1.linux-foundation.org/~mcgrof/2016/07/22/blackfin-fw-dyndbg.config -o .config
> make.cross ARCH=blackfin
> 
> [0] https://lkml.kernel.org/r/1455889559-9428-1-git-send-email-mcgrof@kernel.org
> [1] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linker-tables.git/
> [2] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linux-next.git/log/?h=20160722-linker-table-v3-try2
> [3] https://lkml.kernel.org/r/87y44zhbiu.fsf@rustcorp.com.au
> [4] https://lkml.kernel.org/r/1467327207-14916-1-git-send-email-mcgrof@kernel.org
> [5] http://drvbp1.linux-foundation.org/~mcgrof/2016/07/22/blackfin-fw-dyndbg.config
> 
> 
> Luis R. Rodriguez (13):
>   x86: remove LTO_REFERENCE_INITCALL()
>   dell-smo8800: include uaccess.h
>   scripts/module-common.lds: enable generation
>   sections.h: guard against asm and linker script
>   sections.h: add sections header to collect all section info
>   ranges.h: add helpers to build and identify Linux section ranges
>   tables.h: add linker table support
>   firmware/Makefile: force recompilation if makefile changes
>   firmware: port built-in section to linker table
>   jump_label: port __jump_table to linker tables
>   dynamic_debug: port to use linker tables
>   kprobes: port .kprobes.text to section range
>   kprobes: port blacklist kprobes to linker table
> 
>  .gitignore                                         |   2 +
>  Documentation/DocBook/Makefile                     |   3 +-
>  Documentation/DocBook/linker-tables.tmpl           | 166 ++++++
>  Documentation/DocBook/sections.tmpl                | 112 ++++
>  Documentation/kbuild/makefiles.txt                 |  19 +
>  Makefile                                           |   6 +-
>  arch/alpha/include/asm/ranges.h                    |   6 +
>  arch/alpha/include/asm/sections.h                  |   6 +
>  arch/alpha/include/asm/tables.h                    |   6 +
>  arch/arc/include/asm/ranges.h                      |   6 +
>  arch/arc/include/asm/tables.h                      |   6 +
>  arch/arc/kernel/vmlinux.lds.S                      |   1 -
>  arch/arm/include/asm/jump_label.h                  |   6 +-
>  arch/arm/include/asm/ranges.h                      |   6 +
>  arch/arm/include/asm/sections.h                    |   2 +
>  arch/arm/include/asm/tables.h                      |   6 +
>  arch/arm/kernel/entry-armv.S                       |   3 +-
>  arch/arm/kernel/vmlinux-xip.lds.S                  |   1 -
>  arch/arm/kernel/vmlinux.lds.S                      |   1 -
>  arch/arm64/include/asm/jump_label.h                |   6 +-
>  arch/arm64/include/asm/ranges.h                    |   6 +
>  arch/arm64/include/asm/sections.h                  |   6 +
>  arch/arm64/include/asm/tables.h                    |   6 +
>  arch/avr32/include/asm/ranges.h                    |   6 +
>  arch/avr32/include/asm/sections.h                  |   6 +
>  arch/avr32/include/asm/tables.h                    |   6 +
>  arch/avr32/kernel/entry-avr32b.S                   |   5 +-
>  arch/avr32/kernel/vmlinux.lds.S                    |   1 -
>  arch/blackfin/include/asm/ranges.h                 |   6 +
>  arch/blackfin/include/asm/sections.h               |   4 +
>  arch/blackfin/include/asm/tables.h                 |   6 +
>  arch/blackfin/kernel/vmlinux.lds.S                 |   1 -
>  arch/c6x/include/asm/ranges.h                      |   6 +
>  arch/c6x/include/asm/tables.h                      |   6 +
>  arch/c6x/kernel/vmlinux.lds.S                      |   1 -
>  arch/cris/include/asm/ranges.h                     |   6 +
>  arch/cris/include/asm/sections.h                   |   6 +
>  arch/cris/include/asm/tables.h                     |   6 +
>  arch/frv/include/asm/ranges.h                      |   6 +
>  arch/frv/include/asm/tables.h                      |   6 +
>  arch/h8300/include/asm/ranges.h                    |   6 +
>  arch/h8300/include/asm/sections.h                  |   6 +
>  arch/h8300/include/asm/tables.h                    |   6 +
>  arch/hexagon/include/asm/ranges.h                  |   6 +
>  arch/hexagon/include/asm/sections.h                |   6 +
>  arch/hexagon/include/asm/tables.h                  |   6 +
>  arch/hexagon/kernel/vmlinux.lds.S                  |   1 -
>  arch/ia64/include/asm/ranges.h                     |   6 +
>  arch/ia64/include/asm/sections.h                   |   7 +-
>  arch/ia64/include/asm/tables.h                     |   6 +
>  arch/ia64/kernel/jprobes.S                         |   3 +-
>  arch/ia64/kernel/vmlinux.lds.S                     |   1 -
>  arch/ia64/lib/flush.S                              |   5 +-
>  arch/m32r/include/asm/ranges.h                     |   6 +
>  arch/m32r/include/asm/sections.h                   |   6 +
>  arch/m32r/include/asm/tables.h                     |   6 +
>  arch/m68k/include/asm/ranges.h                     |   6 +
>  arch/m68k/include/asm/sections.h                   |   6 +
>  arch/m68k/include/asm/tables.h                     |   6 +
>  arch/metag/include/asm/ranges.h                    |   6 +
>  arch/metag/include/asm/sections.h                  |   6 +
>  arch/metag/include/asm/tables.h                    |   6 +
>  arch/metag/kernel/vmlinux.lds.S                    |   1 -
>  arch/microblaze/include/asm/ranges.h               |   6 +
>  arch/microblaze/include/asm/tables.h               |   6 +
>  arch/microblaze/kernel/vmlinux.lds.S               |   1 -
>  arch/mips/include/asm/jump_label.h                 |   6 +-
>  arch/mips/include/asm/ranges.h                     |   6 +
>  arch/mips/include/asm/sections.h                   |   6 +
>  arch/mips/include/asm/tables.h                     |   6 +
>  arch/mips/kernel/vmlinux.lds.S                     |   1 -
>  arch/mn10300/include/asm/ranges.h                  |   6 +
>  arch/mn10300/include/asm/sections.h                |   6 +
>  arch/mn10300/include/asm/tables.h                  |   6 +
>  arch/mn10300/kernel/vmlinux.lds.S                  |   1 -
>  arch/nios2/include/asm/ranges.h                    |   6 +
>  arch/nios2/include/asm/sections.h                  |   6 +
>  arch/nios2/include/asm/tables.h                    |   6 +
>  arch/nios2/kernel/vmlinux.lds.S                    |   1 -
>  arch/openrisc/include/asm/ranges.h                 |   6 +
>  arch/openrisc/include/asm/sections.h               |   6 +
>  arch/openrisc/include/asm/tables.h                 |   6 +
>  arch/openrisc/kernel/vmlinux.lds.S                 |   1 -
>  arch/parisc/include/asm/ranges.h                   |   6 +
>  arch/parisc/include/asm/tables.h                   |   6 +
>  arch/parisc/kernel/vmlinux.lds.S                   |   1 -
>  arch/powerpc/include/asm/jump_label.h              |   8 +-
>  arch/powerpc/include/asm/ppc_asm.h                 |   7 +-
>  arch/powerpc/include/asm/ranges.h                  |   6 +
>  arch/powerpc/include/asm/sections.h                |  11 +-
>  arch/powerpc/include/asm/tables.h                  |   6 +
>  arch/powerpc/kernel/vmlinux.lds.S                  |   1 -
>  arch/s390/include/asm/jump_label.h                 |   6 +-
>  arch/s390/include/asm/ranges.h                     |   6 +
>  arch/s390/include/asm/tables.h                     |   6 +
>  arch/s390/kernel/entry.S                           |   5 +-
>  arch/s390/kernel/kprobes.c                         |   6 +-
>  arch/s390/kernel/mcount.S                          |   2 +-
>  arch/s390/kernel/vmlinux.lds.S                     |   1 -
>  arch/score/include/asm/ranges.h                    |   6 +
>  arch/score/include/asm/sections.h                  |   6 +
>  arch/score/include/asm/tables.h                    |   6 +
>  arch/score/kernel/vmlinux.lds.S                    |   1 -
>  arch/sh/include/asm/ranges.h                       |   6 +
>  arch/sh/include/asm/sections.h                     |   2 +
>  arch/sh/include/asm/tables.h                       |   6 +
>  arch/sh/kernel/vmlinux.lds.S                       |   1 -
>  arch/sparc/include/asm/jump_label.h                |   6 +-
>  arch/sparc/include/asm/ranges.h                    |   6 +
>  arch/sparc/include/asm/sections.h                  |   4 +
>  arch/sparc/include/asm/tables.h                    |   6 +
>  arch/sparc/kernel/vmlinux.lds.S                    |   1 -
>  arch/sparc/mm/ultra.S                              |   3 +-
>  arch/tile/include/asm/ranges.h                     |   6 +
>  arch/tile/include/asm/sections.h                   |   4 +
>  arch/tile/include/asm/tables.h                     |   6 +
>  arch/tile/kernel/vmlinux.lds.S                     |   1 -
>  arch/um/include/asm/ranges.h                       |   6 +
>  arch/um/include/asm/tables.h                       |   6 +
>  arch/unicore32/include/asm/ranges.h                |   6 +
>  arch/unicore32/include/asm/sections.h              |   6 +
>  arch/unicore32/include/asm/tables.h                |   6 +
>  arch/x86/include/asm/jump_label.h                  |  10 +-
>  arch/x86/include/asm/ranges.h                      |   6 +
>  arch/x86/include/asm/sections.h                    |  23 +-
>  arch/x86/include/asm/tables.h                      |   6 +
>  arch/x86/include/asm/uaccess.h                     |  18 +-
>  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                            |   3 +
>  arch/xtensa/include/asm/ranges.h                   |   6 +
>  arch/xtensa/include/asm/sections.h                 |   6 +
>  arch/xtensa/include/asm/tables.h                   |   6 +
>  drivers/base/firmware_class.c                      |  12 +-
>  drivers/platform/x86/dell-smo8800.c                |   1 +
>  firmware/Makefile                                  |   7 +-
>  include/asm-generic/ranges.h                       |  70 +++
>  include/asm-generic/sections.h                     | 306 ++++++++++-
>  include/asm-generic/tables.h                       |  70 +++
>  include/asm-generic/vmlinux.lds.h                  |  66 +--
>  include/linux/compiler.h                           |   2 +-
>  include/linux/dynamic_debug.h                      |   5 +-
>  include/linux/init.h                               |  20 +-
>  include/linux/jump_label.h                         |  10 +-
>  include/linux/kprobes.h                            |   8 +-
>  include/linux/ranges.h                             |  54 ++
>  include/linux/sections.h                           | 123 +++++
>  include/linux/tables.h                             | 597 +++++++++++++++++++++
>  kernel/jump_label.c                                |  17 +-
>  kernel/kprobes.c                                   |  17 +-
>  lib/dynamic_debug.c                                |  13 +-
>  scripts/Makefile                                   |   1 +
>  scripts/Makefile.build                             |   4 +-
>  scripts/Makefile.clean                             |   1 +
>  scripts/Makefile.lib                               |  12 +
>  scripts/Makefile.modpost                           |   2 +-
>  scripts/mod/Makefile                               |   2 +
>  scripts/mod/modpost.c                              |   8 +-
>  scripts/{module-common.lds => module-common.lds.S} |   6 +
>  scripts/recordmcount.c                             |   7 +-
>  scripts/recordmcount.pl                            |   2 +-
>  tools/include/linux/sections.h                     |  13 +
>  tools/objtool/special.c                            |   8 +-
>  164 files changed, 2241 insertions(+), 205 deletions(-)
>  create mode 100644 Documentation/DocBook/linker-tables.tmpl
>  create mode 100644 Documentation/DocBook/sections.tmpl
>  create mode 100644 arch/alpha/include/asm/ranges.h
>  create mode 100644 arch/alpha/include/asm/sections.h
>  create mode 100644 arch/alpha/include/asm/tables.h
>  create mode 100644 arch/arc/include/asm/ranges.h
>  create mode 100644 arch/arc/include/asm/tables.h
>  create mode 100644 arch/arm/include/asm/ranges.h
>  create mode 100644 arch/arm/include/asm/tables.h
>  create mode 100644 arch/arm64/include/asm/ranges.h
>  create mode 100644 arch/arm64/include/asm/sections.h
>  create mode 100644 arch/arm64/include/asm/tables.h
>  create mode 100644 arch/avr32/include/asm/ranges.h
>  create mode 100644 arch/avr32/include/asm/sections.h
>  create mode 100644 arch/avr32/include/asm/tables.h
>  create mode 100644 arch/blackfin/include/asm/ranges.h
>  create mode 100644 arch/blackfin/include/asm/tables.h
>  create mode 100644 arch/c6x/include/asm/ranges.h
>  create mode 100644 arch/c6x/include/asm/tables.h
>  create mode 100644 arch/cris/include/asm/ranges.h
>  create mode 100644 arch/cris/include/asm/sections.h
>  create mode 100644 arch/cris/include/asm/tables.h
>  create mode 100644 arch/frv/include/asm/ranges.h
>  create mode 100644 arch/frv/include/asm/tables.h
>  create mode 100644 arch/h8300/include/asm/ranges.h
>  create mode 100644 arch/h8300/include/asm/sections.h
>  create mode 100644 arch/h8300/include/asm/tables.h
>  create mode 100644 arch/hexagon/include/asm/ranges.h
>  create mode 100644 arch/hexagon/include/asm/sections.h
>  create mode 100644 arch/hexagon/include/asm/tables.h
>  create mode 100644 arch/ia64/include/asm/ranges.h
>  create mode 100644 arch/ia64/include/asm/tables.h
>  create mode 100644 arch/m32r/include/asm/ranges.h
>  create mode 100644 arch/m32r/include/asm/sections.h
>  create mode 100644 arch/m32r/include/asm/tables.h
>  create mode 100644 arch/m68k/include/asm/ranges.h
>  create mode 100644 arch/m68k/include/asm/sections.h
>  create mode 100644 arch/m68k/include/asm/tables.h
>  create mode 100644 arch/metag/include/asm/ranges.h
>  create mode 100644 arch/metag/include/asm/sections.h
>  create mode 100644 arch/metag/include/asm/tables.h
>  create mode 100644 arch/microblaze/include/asm/ranges.h
>  create mode 100644 arch/microblaze/include/asm/tables.h
>  create mode 100644 arch/mips/include/asm/ranges.h
>  create mode 100644 arch/mips/include/asm/sections.h
>  create mode 100644 arch/mips/include/asm/tables.h
>  create mode 100644 arch/mn10300/include/asm/ranges.h
>  create mode 100644 arch/mn10300/include/asm/sections.h
>  create mode 100644 arch/mn10300/include/asm/tables.h
>  create mode 100644 arch/nios2/include/asm/ranges.h
>  create mode 100644 arch/nios2/include/asm/sections.h
>  create mode 100644 arch/nios2/include/asm/tables.h
>  create mode 100644 arch/openrisc/include/asm/ranges.h
>  create mode 100644 arch/openrisc/include/asm/sections.h
>  create mode 100644 arch/openrisc/include/asm/tables.h
>  create mode 100644 arch/parisc/include/asm/ranges.h
>  create mode 100644 arch/parisc/include/asm/tables.h
>  create mode 100644 arch/powerpc/include/asm/ranges.h
>  create mode 100644 arch/powerpc/include/asm/tables.h
>  create mode 100644 arch/s390/include/asm/ranges.h
>  create mode 100644 arch/s390/include/asm/tables.h
>  create mode 100644 arch/score/include/asm/ranges.h
>  create mode 100644 arch/score/include/asm/sections.h
>  create mode 100644 arch/score/include/asm/tables.h
>  create mode 100644 arch/sh/include/asm/ranges.h
>  create mode 100644 arch/sh/include/asm/tables.h
>  create mode 100644 arch/sparc/include/asm/ranges.h
>  create mode 100644 arch/sparc/include/asm/tables.h
>  create mode 100644 arch/tile/include/asm/ranges.h
>  create mode 100644 arch/tile/include/asm/tables.h
>  create mode 100644 arch/um/include/asm/ranges.h
>  create mode 100644 arch/um/include/asm/tables.h
>  create mode 100644 arch/unicore32/include/asm/ranges.h
>  create mode 100644 arch/unicore32/include/asm/sections.h
>  create mode 100644 arch/unicore32/include/asm/tables.h
>  create mode 100644 arch/x86/include/asm/ranges.h
>  create mode 100644 arch/x86/include/asm/tables.h
>  create mode 100644 arch/xtensa/include/asm/ranges.h
>  create mode 100644 arch/xtensa/include/asm/sections.h
>  create mode 100644 arch/xtensa/include/asm/tables.h
>  create mode 100644 include/asm-generic/ranges.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%)
>  create mode 100644 tools/include/linux/sections.h
> 
> -- 
> 2.8.4
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
  2016-07-25 13:32   ` Masami Hiramatsu
  (?)
@ 2016-07-25 13:55     ` Richard Fontana
  -1 siblings, 0 replies; 176+ messages in thread
From: Richard Fontana @ 2016-07-25 13:55 UTC (permalink / raw)
  To: Masami Hiramatsu, Luis R. Rodriguez
  Cc: gnomes, linux-ia64, jkosina, benh, ming.lei, heiko.carstens,
	platform-driver-x86, paul.gortmaker, hpa, masami.hiramatsu.pt,
	linux-arch, sparclinux, xen-devel, linux, linux-sh, will.deacon,
	korea.drzix, x86, anil.s.keshavamurthy, torvalds, mingo,
	linux-arm-kernel, catalin.marinas, dvhart, pali.rohar, keescook,
	arnd, realmz6, linux, rusty, rostedt, christopher.denicolo,
	jbaron, ananth, bp, jpoimboe

On 07/25/2016 09:32 AM, Masami Hiramatsu wrote:

> I'm not a lawyer, so I don't know really it is compatible with GPLv2,
> and if it is, I'm not sure the reason why we need another license.
> AFAICS the license terms, most of parts looks reasonable. I just concern
> clause 8, after fifteen years, is that still GPLv2 compatible?
> (I'd like see FAQ about this license...)

Yes, after fifteen years the restrictions in the license that make it
copyleft rather than permissive disappear, and the license is
transformed into a simple, essentially unconditional, permissive open
source license.

Richard



^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-07-25 13:55     ` Richard Fontana
  0 siblings, 0 replies; 176+ messages in thread
From: Richard Fontana @ 2016-07-25 13:55 UTC (permalink / raw)
  To: Masami Hiramatsu, Luis R. Rodriguez
  Cc: gnomes, linux-ia64, jkosina, benh, ming.lei, heiko.carstens,
	platform-driver-x86, paul.gortmaker, hpa, masami.hiramatsu.pt,
	linux-arch, sparclinux, xen-devel, linux, linux-sh, will.deacon,
	korea.drzix, x86, anil.s.keshavamurthy, torvalds, mingo,
	linux-arm-kernel, catalin.marinas, dvhart, pali.rohar, keescook,
	arnd, realmz6, linux, rusty, rostedt, christopher.denicolo,
	jbaron, ananth, bp, jpoimboe

On 07/25/2016 09:32 AM, Masami Hiramatsu wrote:

> I'm not a lawyer, so I don't know really it is compatible with GPLv2,
> and if it is, I'm not sure the reason why we need another license.
> AFAICS the license terms, most of parts looks reasonable. I just concern
> clause 8, after fifteen years, is that still GPLv2 compatible?
> (I'd like see FAQ about this license...)

Yes, after fifteen years the restrictions in the license that make it
copyleft rather than permissive disappear, and the license is
transformed into a simple, essentially unconditional, permissive open
source license.

Richard



_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-07-25 13:55     ` Richard Fontana
  0 siblings, 0 replies; 176+ messages in thread
From: Richard Fontana @ 2016-07-25 13:55 UTC (permalink / raw)
  To: Masami Hiramatsu, Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	ciaran.farrell, christopher.denicolo, david.vrabel, konrad.wilk,
	mcb30, jgross, andrew.cooper3, andriy.shevchenko, paul.gortmaker,
	xen-devel, ak, pali.rohar, dvhart, platform-driver-x86, mmarek,
	linux, jkosina, korea.drzix, linux-kbuild, tony.luck, akpm,
	linux-ia64, linux-arm-kernel, linux-sh, sparclinux,
	catalin.marinas, will.deacon, rostedt, jpoimboe

On 07/25/2016 09:32 AM, Masami Hiramatsu wrote:

> I'm not a lawyer, so I don't know really it is compatible with GPLv2,
> and if it is, I'm not sure the reason why we need another license.
> AFAICS the license terms, most of parts looks reasonable. I just concern
> clause 8, after fifteen years, is that still GPLv2 compatible?
> (I'd like see FAQ about this license...)

Yes, after fifteen years the restrictions in the license that make it
copyleft rather than permissive disappear, and the license is
transformed into a simple, essentially unconditional, permissive open
source license.

Richard



^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 12/13] kprobes: port .kprobes.text to section range
  2016-07-22 21:24   ` Luis R. Rodriguez
  (?)
@ 2016-07-25 15:19     ` Masami Hiramatsu
  -1 siblings, 0 replies; 176+ messages in thread
From: Masami Hiramatsu @ 2016-07-25 15:19 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel

On Fri, 22 Jul 2016 14:24:46 -0700
"Luis R. Rodriguez" <mcgrof@kernel.org> wrote:

> 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

Looks good to me except for the modpost part.

> 
> diff --git a/scripts/Makefile b/scripts/Makefile
> index 1d80897a9644..77a0cc91628c 100644
> --- a/scripts/Makefile
> +++ b/scripts/Makefile
> @@ -10,6 +10,7 @@
>  # check-lc_ctype: Used in Documentation/DocBook
>  
>  HOST_EXTRACFLAGS += -I$(srctree)/tools/include
> +HOST_EXTRACFLAGS += -U__KERNEL__

This looks a add-hoc hack. If we just need SECTION_RNG(SECTION_TEXT, kprobes)
to convert to section name, can we export the definitions outside of _KERNEL_ ?

Thank you,

>  
>  hostprogs-$(CONFIG_KALLSYMS)     += kallsyms
>  hostprogs-$(CONFIG_LOGO)         += pnmtologo
> diff --git a/scripts/mod/Makefile b/scripts/mod/Makefile
> index 8257ef422c0a..76905d4ac0d0 100644
> --- a/scripts/mod/Makefile
> +++ b/scripts/mod/Makefile
> @@ -1,5 +1,7 @@
>  OBJECT_FILES_NON_STANDARD := y
>  
> +HOST_EXTRACFLAGS += -U__KERNEL__
> +
>  hostprogs-y	:= modpost mk_elfconfig
>  always		:= $(hostprogs-y) empty.o
>  
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 48958d3cec9e..12ddced5df84 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -19,10 +19,16 @@
>  #include <stdbool.h>
>  #include <errno.h>
>  #include "modpost.h"
> +
>  #include "../../include/generated/autoconf.h"
>  #include "../../include/linux/license.h"
>  #include "../../include/linux/export.h"
>  
> +#include "../../include/linux/sections.h"
> +#include "../../include/asm-generic/sections.h"
> +#include "../../include/linux/ranges.h"
> +#include "../../include/asm-generic/ranges.h"
> +
>  /* Are we using CONFIG_MODVERSIONS? */
>  static int modversions = 0;
>  /* Warn about undefined symbols? (do so if we have vmlinux) */
> @@ -888,7 +894,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"
> +		SECTION_RNG(SECTION_TEXT, kprobes)
>  #define OTHER_TEXT_SECTIONS ".ref.text", ".head.text", ".spinlock.text", \
>  		".fixup", ".entry.text", ".exception.text", ".text.*", \
>  		".coldtext"
> diff --git a/scripts/recordmcount.c b/scripts/recordmcount.c
> index e167592793a7..8381d75235d4 100644
> --- a/scripts/recordmcount.c
> +++ b/scripts/recordmcount.c
> @@ -33,6 +33,11 @@
>  #include <string.h>
>  #include <unistd.h>
>  
> +#include "../../include/linux/sections.h"
> +#include "../../include/asm-generic/sections.h"
> +#include "../../include/linux/ranges.h"
> +#include "../../include/asm-generic/ranges.h"
> +
>  #ifndef EM_METAG
>  /* Remove this when these make it to the standard system elf.h. */
>  #define EM_METAG      174
> @@ -356,7 +361,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(SECTION_RNG(SECTION_TEXT, kprobe), txtname) = 0 ||
>  		strcmp(".text.unlikely", txtname) = 0;
>  }
>  
> diff --git a/scripts/recordmcount.pl b/scripts/recordmcount.pl
> index 96e2486a6fc4..f663a7c5d6ab 100755
> --- a/scripts/recordmcount.pl
> +++ b/scripts/recordmcount.pl
> @@ -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,
>  );
>  
> -- 
> 2.8.4
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 12/13] kprobes: port .kprobes.text to section range
@ 2016-07-25 15:19     ` Masami Hiramatsu
  0 siblings, 0 replies; 176+ messages in thread
From: Masami Hiramatsu @ 2016-07-25 15:19 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel

On Fri, 22 Jul 2016 14:24:46 -0700
"Luis R. Rodriguez" <mcgrof@kernel.org> wrote:

> 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

Looks good to me except for the modpost part.

> 
> diff --git a/scripts/Makefile b/scripts/Makefile
> index 1d80897a9644..77a0cc91628c 100644
> --- a/scripts/Makefile
> +++ b/scripts/Makefile
> @@ -10,6 +10,7 @@
>  # check-lc_ctype: Used in Documentation/DocBook
>  
>  HOST_EXTRACFLAGS += -I$(srctree)/tools/include
> +HOST_EXTRACFLAGS += -U__KERNEL__

This looks a add-hoc hack. If we just need SECTION_RNG(SECTION_TEXT, kprobes)
to convert to section name, can we export the definitions outside of _KERNEL_ ?

Thank you,

>  
>  hostprogs-$(CONFIG_KALLSYMS)     += kallsyms
>  hostprogs-$(CONFIG_LOGO)         += pnmtologo
> diff --git a/scripts/mod/Makefile b/scripts/mod/Makefile
> index 8257ef422c0a..76905d4ac0d0 100644
> --- a/scripts/mod/Makefile
> +++ b/scripts/mod/Makefile
> @@ -1,5 +1,7 @@
>  OBJECT_FILES_NON_STANDARD := y
>  
> +HOST_EXTRACFLAGS += -U__KERNEL__
> +
>  hostprogs-y	:= modpost mk_elfconfig
>  always		:= $(hostprogs-y) empty.o
>  
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 48958d3cec9e..12ddced5df84 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -19,10 +19,16 @@
>  #include <stdbool.h>
>  #include <errno.h>
>  #include "modpost.h"
> +
>  #include "../../include/generated/autoconf.h"
>  #include "../../include/linux/license.h"
>  #include "../../include/linux/export.h"
>  
> +#include "../../include/linux/sections.h"
> +#include "../../include/asm-generic/sections.h"
> +#include "../../include/linux/ranges.h"
> +#include "../../include/asm-generic/ranges.h"
> +
>  /* Are we using CONFIG_MODVERSIONS? */
>  static int modversions = 0;
>  /* Warn about undefined symbols? (do so if we have vmlinux) */
> @@ -888,7 +894,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"
> +		SECTION_RNG(SECTION_TEXT, kprobes)
>  #define OTHER_TEXT_SECTIONS ".ref.text", ".head.text", ".spinlock.text", \
>  		".fixup", ".entry.text", ".exception.text", ".text.*", \
>  		".coldtext"
> diff --git a/scripts/recordmcount.c b/scripts/recordmcount.c
> index e167592793a7..8381d75235d4 100644
> --- a/scripts/recordmcount.c
> +++ b/scripts/recordmcount.c
> @@ -33,6 +33,11 @@
>  #include <string.h>
>  #include <unistd.h>
>  
> +#include "../../include/linux/sections.h"
> +#include "../../include/asm-generic/sections.h"
> +#include "../../include/linux/ranges.h"
> +#include "../../include/asm-generic/ranges.h"
> +
>  #ifndef EM_METAG
>  /* Remove this when these make it to the standard system elf.h. */
>  #define EM_METAG      174
> @@ -356,7 +361,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(SECTION_RNG(SECTION_TEXT, kprobe), txtname) == 0 ||
>  		strcmp(".text.unlikely", txtname) == 0;
>  }
>  
> diff --git a/scripts/recordmcount.pl b/scripts/recordmcount.pl
> index 96e2486a6fc4..f663a7c5d6ab 100755
> --- a/scripts/recordmcount.pl
> +++ b/scripts/recordmcount.pl
> @@ -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,
>  );
>  
> -- 
> 2.8.4
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 12/13] kprobes: port .kprobes.text to section range
@ 2016-07-25 15:19     ` Masami Hiramatsu
  0 siblings, 0 replies; 176+ messages in thread
From: Masami Hiramatsu @ 2016-07-25 15:19 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe

On Fri, 22 Jul 2016 14:24:46 -0700
"Luis R. Rodriguez" <mcgrof@kernel.org> wrote:

> 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

Looks good to me except for the modpost part.

> 
> diff --git a/scripts/Makefile b/scripts/Makefile
> index 1d80897a9644..77a0cc91628c 100644
> --- a/scripts/Makefile
> +++ b/scripts/Makefile
> @@ -10,6 +10,7 @@
>  # check-lc_ctype: Used in Documentation/DocBook
>  
>  HOST_EXTRACFLAGS += -I$(srctree)/tools/include
> +HOST_EXTRACFLAGS += -U__KERNEL__

This looks a add-hoc hack. If we just need SECTION_RNG(SECTION_TEXT, kprobes)
to convert to section name, can we export the definitions outside of _KERNEL_ ?

Thank you,

>  
>  hostprogs-$(CONFIG_KALLSYMS)     += kallsyms
>  hostprogs-$(CONFIG_LOGO)         += pnmtologo
> diff --git a/scripts/mod/Makefile b/scripts/mod/Makefile
> index 8257ef422c0a..76905d4ac0d0 100644
> --- a/scripts/mod/Makefile
> +++ b/scripts/mod/Makefile
> @@ -1,5 +1,7 @@
>  OBJECT_FILES_NON_STANDARD := y
>  
> +HOST_EXTRACFLAGS += -U__KERNEL__
> +
>  hostprogs-y	:= modpost mk_elfconfig
>  always		:= $(hostprogs-y) empty.o
>  
> diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
> index 48958d3cec9e..12ddced5df84 100644
> --- a/scripts/mod/modpost.c
> +++ b/scripts/mod/modpost.c
> @@ -19,10 +19,16 @@
>  #include <stdbool.h>
>  #include <errno.h>
>  #include "modpost.h"
> +
>  #include "../../include/generated/autoconf.h"
>  #include "../../include/linux/license.h"
>  #include "../../include/linux/export.h"
>  
> +#include "../../include/linux/sections.h"
> +#include "../../include/asm-generic/sections.h"
> +#include "../../include/linux/ranges.h"
> +#include "../../include/asm-generic/ranges.h"
> +
>  /* Are we using CONFIG_MODVERSIONS? */
>  static int modversions = 0;
>  /* Warn about undefined symbols? (do so if we have vmlinux) */
> @@ -888,7 +894,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"
> +		SECTION_RNG(SECTION_TEXT, kprobes)
>  #define OTHER_TEXT_SECTIONS ".ref.text", ".head.text", ".spinlock.text", \
>  		".fixup", ".entry.text", ".exception.text", ".text.*", \
>  		".coldtext"
> diff --git a/scripts/recordmcount.c b/scripts/recordmcount.c
> index e167592793a7..8381d75235d4 100644
> --- a/scripts/recordmcount.c
> +++ b/scripts/recordmcount.c
> @@ -33,6 +33,11 @@
>  #include <string.h>
>  #include <unistd.h>
>  
> +#include "../../include/linux/sections.h"
> +#include "../../include/asm-generic/sections.h"
> +#include "../../include/linux/ranges.h"
> +#include "../../include/asm-generic/ranges.h"
> +
>  #ifndef EM_METAG
>  /* Remove this when these make it to the standard system elf.h. */
>  #define EM_METAG      174
> @@ -356,7 +361,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(SECTION_RNG(SECTION_TEXT, kprobe), txtname) == 0 ||
>  		strcmp(".text.unlikely", txtname) == 0;
>  }
>  
> diff --git a/scripts/recordmcount.pl b/scripts/recordmcount.pl
> index 96e2486a6fc4..f663a7c5d6ab 100755
> --- a/scripts/recordmcount.pl
> +++ b/scripts/recordmcount.pl
> @@ -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,
>  );
>  
> -- 
> 2.8.4
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 13/13] kprobes: port blacklist kprobes to linker table
  2016-07-22 21:24   ` Luis R. Rodriguez
  (?)
@ 2016-07-25 15:27     ` Masami Hiramatsu
  -1 siblings, 0 replies; 176+ messages in thread
From: Masami Hiramatsu @ 2016-07-25 15:27 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel

On Fri, 22 Jul 2016 14:24:47 -0700
"Luis R. Rodriguez" <mcgrof@kernel.org> wrote:

> 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:

This is OK for me, and if you would like to make sure, please use ftrace to probe
 (easier  than making new module) and compare debugfs/blacklist which shows
all blacklisted functions, so if all the function names are same it
must be OK :).

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>


Thank you,

> 
>  # 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
> 
> Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
> ---
>  include/asm-generic/vmlinux.lds.h | 10 ----------
>  include/linux/kprobes.h           |  5 +++--
>  kernel/kprobes.c                  | 11 ++++-------
>  3 files changed, 7 insertions(+), 19 deletions(-)
> 
> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> index 1664050e6560..0e4df8c61c18 100644
> --- a/include/asm-generic/vmlinux.lds.h
> +++ b/include/asm-generic/vmlinux.lds.h
> @@ -113,15 +113,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) = .;	\
> @@ -519,7 +510,6 @@
>  	*(SECTION_INIT_RODATA)						\
>  	FTRACE_EVENTS()							\
>  	TRACE_SYSCALLS()						\
> -	KPROBE_BLACKLIST()						\
>  	MEM_DISCARD(init.rodata)					\
>  	CLK_OF_TABLES()							\
>  	RESERVEDMEM_OF_TABLES()						\
> diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
> index 3f46b282a3f9..c9bb9caef70c 100644
> --- a/include/linux/kprobes.h
> +++ b/include/linux/kprobes.h
> @@ -43,9 +43,11 @@
>  
>  #ifdef CONFIG_KPROBES
>  #include <linux/ranges.h>
> +#include <linux/tables.h>
>  #include <asm/kprobes.h>
>  
>  DECLARE_SECTION_RANGE(kprobes);
> +DECLARE_LINKTABLE(unsigned long, _kprobe_blacklist);
>  
>  /* kprobe_status settings */
>  #define KPROBE_HIT_ACTIVE	0x00000001
> @@ -490,8 +492,7 @@ static inline int enable_jprobe(struct jprobe *jp)
>   * 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)
>  #else
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 387605682622..4801aa3b4adf 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -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");
> -- 
> 2.8.4
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 13/13] kprobes: port blacklist kprobes to linker table
@ 2016-07-25 15:27     ` Masami Hiramatsu
  0 siblings, 0 replies; 176+ messages in thread
From: Masami Hiramatsu @ 2016-07-25 15:27 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel

On Fri, 22 Jul 2016 14:24:47 -0700
"Luis R. Rodriguez" <mcgrof@kernel.org> wrote:

> 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:

This is OK for me, and if you would like to make sure, please use ftrace to probe
 (easier  than making new module) and compare debugfs/blacklist which shows
all blacklisted functions, so if all the function names are same it
must be OK :).

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>


Thank you,

> 
>  # 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
> 
> Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
> ---
>  include/asm-generic/vmlinux.lds.h | 10 ----------
>  include/linux/kprobes.h           |  5 +++--
>  kernel/kprobes.c                  | 11 ++++-------
>  3 files changed, 7 insertions(+), 19 deletions(-)
> 
> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> index 1664050e6560..0e4df8c61c18 100644
> --- a/include/asm-generic/vmlinux.lds.h
> +++ b/include/asm-generic/vmlinux.lds.h
> @@ -113,15 +113,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) = .;	\
> @@ -519,7 +510,6 @@
>  	*(SECTION_INIT_RODATA)						\
>  	FTRACE_EVENTS()							\
>  	TRACE_SYSCALLS()						\
> -	KPROBE_BLACKLIST()						\
>  	MEM_DISCARD(init.rodata)					\
>  	CLK_OF_TABLES()							\
>  	RESERVEDMEM_OF_TABLES()						\
> diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
> index 3f46b282a3f9..c9bb9caef70c 100644
> --- a/include/linux/kprobes.h
> +++ b/include/linux/kprobes.h
> @@ -43,9 +43,11 @@
>  
>  #ifdef CONFIG_KPROBES
>  #include <linux/ranges.h>
> +#include <linux/tables.h>
>  #include <asm/kprobes.h>
>  
>  DECLARE_SECTION_RANGE(kprobes);
> +DECLARE_LINKTABLE(unsigned long, _kprobe_blacklist);
>  
>  /* kprobe_status settings */
>  #define KPROBE_HIT_ACTIVE	0x00000001
> @@ -490,8 +492,7 @@ static inline int enable_jprobe(struct jprobe *jp)
>   * 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)
>  #else
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 387605682622..4801aa3b4adf 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -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");
> -- 
> 2.8.4
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 13/13] kprobes: port blacklist kprobes to linker table
@ 2016-07-25 15:27     ` Masami Hiramatsu
  0 siblings, 0 replies; 176+ messages in thread
From: Masami Hiramatsu @ 2016-07-25 15:27 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe

On Fri, 22 Jul 2016 14:24:47 -0700
"Luis R. Rodriguez" <mcgrof@kernel.org> wrote:

> 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:

This is OK for me, and if you would like to make sure, please use ftrace to probe
 (easier  than making new module) and compare debugfs/blacklist which shows
all blacklisted functions, so if all the function names are same it
must be OK :).

Acked-by: Masami Hiramatsu <mhiramat@kernel.org>


Thank you,

> 
>  # 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
> 
> Signed-off-by: Luis R. Rodriguez <mcgrof@kernel.org>
> ---
>  include/asm-generic/vmlinux.lds.h | 10 ----------
>  include/linux/kprobes.h           |  5 +++--
>  kernel/kprobes.c                  | 11 ++++-------
>  3 files changed, 7 insertions(+), 19 deletions(-)
> 
> diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
> index 1664050e6560..0e4df8c61c18 100644
> --- a/include/asm-generic/vmlinux.lds.h
> +++ b/include/asm-generic/vmlinux.lds.h
> @@ -113,15 +113,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) = .;	\
> @@ -519,7 +510,6 @@
>  	*(SECTION_INIT_RODATA)						\
>  	FTRACE_EVENTS()							\
>  	TRACE_SYSCALLS()						\
> -	KPROBE_BLACKLIST()						\
>  	MEM_DISCARD(init.rodata)					\
>  	CLK_OF_TABLES()							\
>  	RESERVEDMEM_OF_TABLES()						\
> diff --git a/include/linux/kprobes.h b/include/linux/kprobes.h
> index 3f46b282a3f9..c9bb9caef70c 100644
> --- a/include/linux/kprobes.h
> +++ b/include/linux/kprobes.h
> @@ -43,9 +43,11 @@
>  
>  #ifdef CONFIG_KPROBES
>  #include <linux/ranges.h>
> +#include <linux/tables.h>
>  #include <asm/kprobes.h>
>  
>  DECLARE_SECTION_RANGE(kprobes);
> +DECLARE_LINKTABLE(unsigned long, _kprobe_blacklist);
>  
>  /* kprobe_status settings */
>  #define KPROBE_HIT_ACTIVE	0x00000001
> @@ -490,8 +492,7 @@ static inline int enable_jprobe(struct jprobe *jp)
>   * 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)
>  #else
> diff --git a/kernel/kprobes.c b/kernel/kprobes.c
> index 387605682622..4801aa3b4adf 100644
> --- a/kernel/kprobes.c
> +++ b/kernel/kprobes.c
> @@ -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");
> -- 
> 2.8.4
> 


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-07-22 21:24   ` Luis R. Rodriguez
  (?)
@ 2016-07-25 15:30     ` Masami Hiramatsu
  -1 siblings, 0 replies; 176+ messages in thread
From: Masami Hiramatsu @ 2016-07-25 15:30 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel

On Fri, 22 Jul 2016 14:24:41 -0700
"Luis R. Rodriguez" <mcgrof@kernel.org> wrote:

> +/**
> + * LINKTABLE_RUN_ALL - iterate and run through all entries on a linker table
> + *
> + * @tbl: linker table
> + * @func: structure name for the function name we want to call.
> + * @args...: arguments to pass to func
> + *
> + * Example usage:
> + *
> + *   LINKTABLE_RUN_ALL(frobnicator_fns, some_run,);
> + */
> +#define LINKTABLE_RUN_ALL(tbl, func, args...)				\
> +do {									\
> +	size_t i;							\
> +	for (i = 0; i < LINUX_SECTION_SIZE(tbl); i++)			\
> +		(tbl[i]).func (args);					\
> +} while (0);
> +
> +/**
> + * LINKTABLE_RUN_ERR - run each linker table entry func and return error if any
> + *
> + * @tbl: linker table
> + * @func: structure name for the function name we want to call.
> + * @args...: arguments to pass to func
> + *
> + * Example usage:
> + *
> + *   unsigned int err = LINKTABLE_RUN_ERR(frobnicator_fns, some_run,);
> + */
> +#define LINKTABLE_RUN_ERR(tbl, func, args...)				\
> +({									\
> +	size_t i;							\
> +	int err = 0;							\
> +	for (i = 0; !err && i < LINUX_SECTION_SIZE(tbl); i++)		\
> +		err = (tbl[i]).func (args);				\
> +		err; \
> +})

These iteration APIs are a bit dangerous, at least for these APIs we'd better change
name like as FUNCTABLE_RUN etc. because LINKTABLE can contain not only function address
but also some data (or address of data).

Thank  you,


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-07-25 15:30     ` Masami Hiramatsu
  0 siblings, 0 replies; 176+ messages in thread
From: Masami Hiramatsu @ 2016-07-25 15:30 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel

On Fri, 22 Jul 2016 14:24:41 -0700
"Luis R. Rodriguez" <mcgrof@kernel.org> wrote:

> +/**
> + * LINKTABLE_RUN_ALL - iterate and run through all entries on a linker table
> + *
> + * @tbl: linker table
> + * @func: structure name for the function name we want to call.
> + * @args...: arguments to pass to func
> + *
> + * Example usage:
> + *
> + *   LINKTABLE_RUN_ALL(frobnicator_fns, some_run,);
> + */
> +#define LINKTABLE_RUN_ALL(tbl, func, args...)				\
> +do {									\
> +	size_t i;							\
> +	for (i = 0; i < LINUX_SECTION_SIZE(tbl); i++)			\
> +		(tbl[i]).func (args);					\
> +} while (0);
> +
> +/**
> + * LINKTABLE_RUN_ERR - run each linker table entry func and return error if any
> + *
> + * @tbl: linker table
> + * @func: structure name for the function name we want to call.
> + * @args...: arguments to pass to func
> + *
> + * Example usage:
> + *
> + *   unsigned int err = LINKTABLE_RUN_ERR(frobnicator_fns, some_run,);
> + */
> +#define LINKTABLE_RUN_ERR(tbl, func, args...)				\
> +({									\
> +	size_t i;							\
> +	int err = 0;							\
> +	for (i = 0; !err && i < LINUX_SECTION_SIZE(tbl); i++)		\
> +		err = (tbl[i]).func (args);				\
> +		err; \
> +})

These iteration APIs are a bit dangerous, at least for these APIs we'd better change
name like as FUNCTABLE_RUN etc. because LINKTABLE can contain not only function address
but also some data (or address of data).

Thank  you,


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-07-25 15:30     ` Masami Hiramatsu
  0 siblings, 0 replies; 176+ messages in thread
From: Masami Hiramatsu @ 2016-07-25 15:30 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe

On Fri, 22 Jul 2016 14:24:41 -0700
"Luis R. Rodriguez" <mcgrof@kernel.org> wrote:

> +/**
> + * LINKTABLE_RUN_ALL - iterate and run through all entries on a linker table
> + *
> + * @tbl: linker table
> + * @func: structure name for the function name we want to call.
> + * @args...: arguments to pass to func
> + *
> + * Example usage:
> + *
> + *   LINKTABLE_RUN_ALL(frobnicator_fns, some_run,);
> + */
> +#define LINKTABLE_RUN_ALL(tbl, func, args...)				\
> +do {									\
> +	size_t i;							\
> +	for (i = 0; i < LINUX_SECTION_SIZE(tbl); i++)			\
> +		(tbl[i]).func (args);					\
> +} while (0);
> +
> +/**
> + * LINKTABLE_RUN_ERR - run each linker table entry func and return error if any
> + *
> + * @tbl: linker table
> + * @func: structure name for the function name we want to call.
> + * @args...: arguments to pass to func
> + *
> + * Example usage:
> + *
> + *   unsigned int err = LINKTABLE_RUN_ERR(frobnicator_fns, some_run,);
> + */
> +#define LINKTABLE_RUN_ERR(tbl, func, args...)				\
> +({									\
> +	size_t i;							\
> +	int err = 0;							\
> +	for (i = 0; !err && i < LINUX_SECTION_SIZE(tbl); i++)		\
> +		err = (tbl[i]).func (args);				\
> +		err; \
> +})

These iteration APIs are a bit dangerous, at least for these APIs we'd better change
name like as FUNCTABLE_RUN etc. because LINKTABLE can contain not only function address
but also some data (or address of data).

Thank  you,


-- 
Masami Hiramatsu <mhiramat@kernel.org>

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
  2016-07-22 21:24 ` Luis R. Rodriguez
                   ` (15 preceding siblings ...)
  (?)
@ 2016-07-27 22:27 ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-27 22:27 UTC (permalink / raw)
  To: Steven Miao; +Cc: adi-buildroot-devel, linux-kernel

On Fri, Jul 22, 2016 at 02:24:34PM -0700, Luis R. Rodriguez wrote:
<-- snip -->

> This all goes tested by 0-day... however since I found an issue with linker
> tables and blackfin this series remains as RFC -- I'll try to debug the
> issue with Steven Miao. The issue with blackfin is using a config that
> enables CONFIG_FW_LOADER=y and CONFIG_DYNAMIC_DEBUG=y [5] we end up with
> the following at final link time:
> 
>   LD      init/built-in.o
> lib/built-in.o: In function `dynamic_debug_init':
> lib/dynamic_debug.c:(.init.text+0x156): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x15a): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x160): undefined reference to `__verbose'
> lib/dynamic_debug.c:(.init.text+0x164): undefined reference to `__verbose'
> lib/dynamic_debug.c:(.init.text+0x214): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x218): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x252): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x258): undefined reference to `__verbose'
> lib/dynamic_debug.c:(.init.text+0x25c): undefined reference to `__verbose__end'
> lib/dynamic_debug.c:(.init.text+0x260): undefined reference to `__verbose'
> drivers/built-in.o: In function `release_firmware':
> (.text+0x22dc2): undefined reference to `builtin_fw'
> drivers/built-in.o: In function `release_firmware':
> (.text+0x22dc6): undefined reference to `builtin_fw__end'
> drivers/built-in.o: In function `release_firmware':
> (.text+0x22dca): undefined reference to `builtin_fw'
> drivers/built-in.o: In function `release_firmware':
> (.text+0x22dce): undefined reference to `builtin_fw__end'
> drivers/built-in.o: In function `fw_get_builtin_firmware':
> drivers/base/firmware_class.c:(.text+0x23008): undefined reference to `builtin_fw'
> drivers/base/firmware_class.c:(.text+0x2300c): undefined reference to `builtin_fw__end'
> drivers/base/firmware_class.c:(.text+0x23010): undefined reference to `builtin_fw'
> drivers/base/firmware_class.c:(.text+0x23014): undefined reference to `builtin_fw__end'
> Makefile:957: recipe for target 'vmlinux' failed
> make: *** [vmlinux] Error 1
> 
> To reproduce then:
> 
> wget https://git.kernel.org/cgit/linux/kernel/git/wfg/lkp-tests.git/plain/sbin/make.cross -O ~/bin/make.cross
> chmod +x ~/bin/make.cross
> wget http://drvbp1.linux-foundation.org/~mcgrof/2016/07/22/blackfin-fw-dyndbg.config -o .config
> make.cross ARCH=blackfin
> 
> [0] https://lkml.kernel.org/r/1455889559-9428-1-git-send-email-mcgrof@kernel.org
> [1] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linker-tables.git/
> [2] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linux-next.git/log/?h=20160722-linker-table-v3-try2
> [3] https://lkml.kernel.org/r/87y44zhbiu.fsf@rustcorp.com.au
> [4] https://lkml.kernel.org/r/1467327207-14916-1-git-send-email-mcgrof@kernel.org
> [5] http://drvbp1.linux-foundation.org/~mcgrof/2016/07/22/blackfin-fw-dyndbg.config

Steven, curious if you've had a chance to look into this. I cannot help but
suspect this is an issue of the blackfin linker as it only happens on blackfin.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 12/13] kprobes: port .kprobes.text to section range
  2016-07-25 15:19     ` Masami Hiramatsu
  (?)
@ 2016-07-27 22:40       ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-27 22:40 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko

On Tue, Jul 26, 2016 at 12:19:58AM +0900, Masami Hiramatsu wrote:
> On Fri, 22 Jul 2016 14:24:46 -0700
> "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
> 
> > 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
> 
> Looks good to me except for the modpost part.

OK thanks!

> > diff --git a/scripts/Makefile b/scripts/Makefile
> > index 1d80897a9644..77a0cc91628c 100644
> > --- a/scripts/Makefile
> > +++ b/scripts/Makefile
> > @@ -10,6 +10,7 @@
> >  # check-lc_ctype: Used in Documentation/DocBook
> >  
> >  HOST_EXTRACFLAGS += -I$(srctree)/tools/include
> > +HOST_EXTRACFLAGS += -U__KERNEL__
> 
> This looks a add-hoc hack. If we just need SECTION_RNG(SECTION_TEXT, kprobes)
> to convert to section name, can we export the definitions outside of _KERNEL_ ?

We can, it was just a matter of deciding if we were OK with open coding the
section, copying over some defines, or sharing somehow (this was one way) the
header files.

Josh seems to prefer to open coding out the names on the tools we can certanly
do that here as well, I think his point that the names should/will likely
never change is sufficient motivation to avoid all this and prefer open coding
this.

Will do that in the next spin unless I hear otherwise.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 12/13] kprobes: port .kprobes.text to section range
@ 2016-07-27 22:40       ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-27 22:40 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko

On Tue, Jul 26, 2016 at 12:19:58AM +0900, Masami Hiramatsu wrote:
> On Fri, 22 Jul 2016 14:24:46 -0700
> "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
> 
> > 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
> 
> Looks good to me except for the modpost part.

OK thanks!

> > diff --git a/scripts/Makefile b/scripts/Makefile
> > index 1d80897a9644..77a0cc91628c 100644
> > --- a/scripts/Makefile
> > +++ b/scripts/Makefile
> > @@ -10,6 +10,7 @@
> >  # check-lc_ctype: Used in Documentation/DocBook
> >  
> >  HOST_EXTRACFLAGS += -I$(srctree)/tools/include
> > +HOST_EXTRACFLAGS += -U__KERNEL__
> 
> This looks a add-hoc hack. If we just need SECTION_RNG(SECTION_TEXT, kprobes)
> to convert to section name, can we export the definitions outside of _KERNEL_ ?

We can, it was just a matter of deciding if we were OK with open coding the
section, copying over some defines, or sharing somehow (this was one way) the
header files.

Josh seems to prefer to open coding out the names on the tools we can certanly
do that here as well, I think his point that the names should/will likely
never change is sufficient motivation to avoid all this and prefer open coding
this.

Will do that in the next spin unless I hear otherwise.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 12/13] kprobes: port .kprobes.text to section range
@ 2016-07-27 22:40       ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-27 22:40 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker, xen-devel, ak,
	pali.rohar, dvhart, platform-driver-x86, mmarek, linux, jkosina,
	korea.drzix, linux-kbuild, tony.luck, akpm, linux-ia64,
	linux-arm-kernel, linux-sh, sparclinux, catalin.marinas,
	will.deacon, rostedt, jpoimboe

On Tue, Jul 26, 2016 at 12:19:58AM +0900, Masami Hiramatsu wrote:
> On Fri, 22 Jul 2016 14:24:46 -0700
> "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
> 
> > 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
> 
> Looks good to me except for the modpost part.

OK thanks!

> > diff --git a/scripts/Makefile b/scripts/Makefile
> > index 1d80897a9644..77a0cc91628c 100644
> > --- a/scripts/Makefile
> > +++ b/scripts/Makefile
> > @@ -10,6 +10,7 @@
> >  # check-lc_ctype: Used in Documentation/DocBook
> >  
> >  HOST_EXTRACFLAGS += -I$(srctree)/tools/include
> > +HOST_EXTRACFLAGS += -U__KERNEL__
> 
> This looks a add-hoc hack. If we just need SECTION_RNG(SECTION_TEXT, kprobes)
> to convert to section name, can we export the definitions outside of _KERNEL_ ?

We can, it was just a matter of deciding if we were OK with open coding the
section, copying over some defines, or sharing somehow (this was one way) the
header files.

Josh seems to prefer to open coding out the names on the tools we can certanly
do that here as well, I think his point that the names should/will likely
never change is sufficient motivation to avoid all this and prefer open coding
this.

Will do that in the next spin unless I hear otherwise.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
  2016-07-25 13:32   ` Masami Hiramatsu
  (?)
@ 2016-07-27 22:46     ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-27 22:46 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko

On Mon, Jul 25, 2016 at 10:32:29PM +0900, Masami Hiramatsu wrote:
> Hi Luis,
> 
> On Fri, 22 Jul 2016 14:24:34 -0700
> "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
> 
> > This RFC v3 builds off the last RFC v2 series [0] for adding linker tables.
> > The largest amount of work here was to take Russell King's feedback on
> > using linker table for kprobes text not being appropriate -- and providing
> > another lightweight API for simple section ranges: read-only stitched pieces
> > of executable code. This required also generalizing common building blocks
> > for both linker tables and section ranges, these building blocks are defined
> > now in include/linux/sections.h and asm-generic/section.h. The other last thing
> > decided was to not support sub-sections. In the hunt for this I could think of
> > anything that really required this, and if it was needed it did not seem
> > impossible to port over to avoid its use. Please let me know if there are valid
> > uses cases for sub-sections.
> > 
> > Other significant effort here was to provide a set of common assembly helpers
> > which could be used across architectures, this starts off some of this work
> > for generic helpers which carve out and define custom Linux sections.
> > 
> > Lastly, this now also goes with two ports which required module support when
> > using linker tables: jump labels, and dynamic debug support. A few
> > extensions have been made to the original series in order to provide
> > support for that.
> > 
> > Since kprobes actually had both a linker table and a section range the
> > patch that dealt with kprobes is now split off in two patches, one
> > that deals with its linker table and another for its section ranges.
> > 
> > More elaborate uses for linker tables are possible, I'll hold off on any
> > of this type of work until at least the basic building blocks are fleshed
> > out. To review how this work came about, and more elaborate uses being
> > evaluated check out the userspace linker-tables mockup solution [1].
> > Hopefully most of the possible bikeshedding was already dealt with through
> > that tree. Thanks to hpa for tons of feedback.
> 
> Great! so table and ranges completely replace the old-style(add-hoc)
> _kprobe and NOKPROBE_SYMBOL() implementation, good job! :)

Indeed, thanks! In reality this is generalizing custom section hacks, but also
making them much more powerful due to the fact that we sort now at link time,
this buys us better than O(1) sort for code where dependencies can be spelled
out in code, it also expands on the semantics available to us for order
levels -- so we're no longer restricted to 7 levels for built-in code -- and
order levels can be subject/subsystem specific.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-07-27 22:46     ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-27 22:46 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko

On Mon, Jul 25, 2016 at 10:32:29PM +0900, Masami Hiramatsu wrote:
> Hi Luis,
> 
> On Fri, 22 Jul 2016 14:24:34 -0700
> "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
> 
> > This RFC v3 builds off the last RFC v2 series [0] for adding linker tables.
> > The largest amount of work here was to take Russell King's feedback on
> > using linker table for kprobes text not being appropriate -- and providing
> > another lightweight API for simple section ranges: read-only stitched pieces
> > of executable code. This required also generalizing common building blocks
> > for both linker tables and section ranges, these building blocks are defined
> > now in include/linux/sections.h and asm-generic/section.h. The other last thing
> > decided was to not support sub-sections. In the hunt for this I could think of
> > anything that really required this, and if it was needed it did not seem
> > impossible to port over to avoid its use. Please let me know if there are valid
> > uses cases for sub-sections.
> > 
> > Other significant effort here was to provide a set of common assembly helpers
> > which could be used across architectures, this starts off some of this work
> > for generic helpers which carve out and define custom Linux sections.
> > 
> > Lastly, this now also goes with two ports which required module support when
> > using linker tables: jump labels, and dynamic debug support. A few
> > extensions have been made to the original series in order to provide
> > support for that.
> > 
> > Since kprobes actually had both a linker table and a section range the
> > patch that dealt with kprobes is now split off in two patches, one
> > that deals with its linker table and another for its section ranges.
> > 
> > More elaborate uses for linker tables are possible, I'll hold off on any
> > of this type of work until at least the basic building blocks are fleshed
> > out. To review how this work came about, and more elaborate uses being
> > evaluated check out the userspace linker-tables mockup solution [1].
> > Hopefully most of the possible bikeshedding was already dealt with through
> > that tree. Thanks to hpa for tons of feedback.
> 
> Great! so table and ranges completely replace the old-style(add-hoc)
> _kprobe and NOKPROBE_SYMBOL() implementation, good job! :)

Indeed, thanks! In reality this is generalizing custom section hacks, but also
making them much more powerful due to the fact that we sort now at link time,
this buys us better than O(1) sort for code where dependencies can be spelled
out in code, it also expands on the semantics available to us for order
levels -- so we're no longer restricted to 7 levels for built-in code -- and
order levels can be subject/subsystem specific.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-07-27 22:46     ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-27 22:46 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker, xen-devel, ak,
	pali.rohar, dvhart, platform-driver-x86, mmarek, linux, jkosina,
	korea.drzix, linux-kbuild, tony.luck, akpm, linux-ia64,
	linux-arm-kernel, linux-sh, sparclinux, catalin.marinas,
	will.deacon, rostedt, jpoimboe

On Mon, Jul 25, 2016 at 10:32:29PM +0900, Masami Hiramatsu wrote:
> Hi Luis,
> 
> On Fri, 22 Jul 2016 14:24:34 -0700
> "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
> 
> > This RFC v3 builds off the last RFC v2 series [0] for adding linker tables.
> > The largest amount of work here was to take Russell King's feedback on
> > using linker table for kprobes text not being appropriate -- and providing
> > another lightweight API for simple section ranges: read-only stitched pieces
> > of executable code. This required also generalizing common building blocks
> > for both linker tables and section ranges, these building blocks are defined
> > now in include/linux/sections.h and asm-generic/section.h. The other last thing
> > decided was to not support sub-sections. In the hunt for this I could think of
> > anything that really required this, and if it was needed it did not seem
> > impossible to port over to avoid its use. Please let me know if there are valid
> > uses cases for sub-sections.
> > 
> > Other significant effort here was to provide a set of common assembly helpers
> > which could be used across architectures, this starts off some of this work
> > for generic helpers which carve out and define custom Linux sections.
> > 
> > Lastly, this now also goes with two ports which required module support when
> > using linker tables: jump labels, and dynamic debug support. A few
> > extensions have been made to the original series in order to provide
> > support for that.
> > 
> > Since kprobes actually had both a linker table and a section range the
> > patch that dealt with kprobes is now split off in two patches, one
> > that deals with its linker table and another for its section ranges.
> > 
> > More elaborate uses for linker tables are possible, I'll hold off on any
> > of this type of work until at least the basic building blocks are fleshed
> > out. To review how this work came about, and more elaborate uses being
> > evaluated check out the userspace linker-tables mockup solution [1].
> > Hopefully most of the possible bikeshedding was already dealt with through
> > that tree. Thanks to hpa for tons of feedback.
> 
> Great! so table and ranges completely replace the old-style(add-hoc)
> _kprobe and NOKPROBE_SYMBOL() implementation, good job! :)

Indeed, thanks! In reality this is generalizing custom section hacks, but also
making them much more powerful due to the fact that we sort now at link time,
this buys us better than O(1) sort for code where dependencies can be spelled
out in code, it also expands on the semantics available to us for order
levels -- so we're no longer restricted to 7 levels for built-in code -- and
order levels can be subject/subsystem specific.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 10/13] jump_label: port __jump_table to linker tables
  2016-07-22 22:55         ` Josh Poimboeuf
  (?)
@ 2016-07-27 22:55           ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-27 22:55 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevche

On Fri, Jul 22, 2016 at 05:55:35PM -0500, Josh Poimboeuf wrote:
> On Sat, Jul 23, 2016 at 12:26:54AM +0200, Luis R. Rodriguez wrote:
> > On Fri, Jul 22, 2016 at 04:49:45PM -0500, Josh Poimboeuf wrote:
> > > On Fri, Jul 22, 2016 at 02:24:44PM -0700, Luis R. Rodriguez wrote:
> > > > diff --git a/tools/objtool/special.c b/tools/objtool/special.c
> > > > index bff8abb3a4aa..f0ad369f994b 100644
> > > > --- a/tools/objtool/special.c
> > > > +++ b/tools/objtool/special.c
> > > > @@ -26,6 +26,10 @@
> > > >  #include "special.h"
> > > >  #include "warn.h"
> > > >  
> > > > +#include "../../include/asm-generic/sections.h"
> > > > +#include "../../include/asm-generic/tables.h"
> > > > +#include "../../include/linux/stringify.h"
> > > > +
> > > >  #define EX_ENTRY_SIZE		12
> > > >  #define EX_ORIG_OFFSET		0
> > > >  #define EX_NEW_OFFSET		4
> > > > @@ -63,7 +67,9 @@ struct special_entry entries[] = {
> > > >  		.feature = ALT_FEATURE_OFFSET,
> > > >  	},
> > > >  	{
> > > > -		.sec = "__jump_table",
> > > > +		.sec = __stringify(SECTION_TBL(SECTION_DATA,
> > > > +				               __jump_table,
> > > > +					       SECTION_ORDER_ANY)),
> > > >  		.jump_or_nop = true,
> > > >  		.size = JUMP_ENTRY_SIZE,
> > > >  		.orig = JUMP_ORIG_OFFSET,
> > > 
> > > (continuing our discussion from another thread...)
> > > 
> > > I think tools code isn't allowed to include kernel files because the
> > > tools subdirectory is supposed to be completely independent.
> > 
> > That was also the case for userpsace tools in scripts/ -- for instance
> > scripts/mod/modpost.c made an exception. What I've proposed here to
> > keep things simple was to ensure -UKERNEL is passed and then only
> > include files we know will work.
> > 
> > Refer to the patch "kprobes: port .kprobes.text to section range"
> > in this series for an extension of the scripts/mod/modpost.c kernel
> > headers use.
> 
> I think the rule of separating code is stricter for tools/ than it is
> for scripts/.  The scripts are generally kernel-specific whereas the
> tools are independent.  I believe the goal is to be able to copy them
> out of the kernel tree and still be able to compile them.

I see.

> > > As far as I can tell, the section name will always be
> > > ".data.tbl.__jump_table.any".  Is that true?  If so, any reason why we
> > > can't just hard-code the string here?
> > 
> > Its a fair strategy, however if upstream changes the order name we'd
> > have to hand code this as well, by using a macro we keep it all in one
> > place.
> 
> Hm, do you expect the section name to change often?

Nope, if anything only upon deployment on major distributions due to
some perhaps compatibility thing with custom hacks folks may have carried
and this just ended up clashing with. The only other case I can think
of a need for a change would be if upstream linkers supported something
similar for another brand of section names, with the added gain that
we would then not even need the 2 new lines on the kernel linker script
for section ranges and tables per section.

> > > As you saw, if the string
> > > changes, objtool will complain and 0-day will report it.
> > 
> > Indeed, which is why I was hoping to instead stick to a standard
> > sections set of header files that lets us get these in on place.
> 
> Actually, I meant that obtool reporting the change would be a good
> thing, in favor of just hard-coding the string.  It lets objtool do its
> job of letting us know when something changes, like it did today.

Getting a report so you can fix something is one reason to have a tool,
having it so you can inspect changes is another. So it depends what uses
there are for objtool. I take it that for this case we do want upstream
objtool to embrace the new section name to avoid further reports as
issues ?

> > The only place I hand coded in this series was in the perl
> > file scripts/recordmcount.pl but I suppose if we wanted to get
> > creative we could even generate a header for it too.
> > 
> > If we want to avoid all this hacker include stuff another option
> > is to *generate* each respective sections.h for the kernel, and
> > also, one for tools, and one for perl. What do you think?
> 
> If the generated files aren't checked into git, tools/ will rely on
> kernel files and will no longer be independent.  If they *are* checked
> in, then we have to keep the files in sync.  Either way it sounds like
> overkill, just to avoid hard-coding a string for which objtool will
> already warn if it changes.

We can open code the string, that's fine. In retrospect since things
won't change often that keeps things simple.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 10/13] jump_label: port __jump_table to linker tables
@ 2016-07-27 22:55           ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-27 22:55 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevche

On Fri, Jul 22, 2016 at 05:55:35PM -0500, Josh Poimboeuf wrote:
> On Sat, Jul 23, 2016 at 12:26:54AM +0200, Luis R. Rodriguez wrote:
> > On Fri, Jul 22, 2016 at 04:49:45PM -0500, Josh Poimboeuf wrote:
> > > On Fri, Jul 22, 2016 at 02:24:44PM -0700, Luis R. Rodriguez wrote:
> > > > diff --git a/tools/objtool/special.c b/tools/objtool/special.c
> > > > index bff8abb3a4aa..f0ad369f994b 100644
> > > > --- a/tools/objtool/special.c
> > > > +++ b/tools/objtool/special.c
> > > > @@ -26,6 +26,10 @@
> > > >  #include "special.h"
> > > >  #include "warn.h"
> > > >  
> > > > +#include "../../include/asm-generic/sections.h"
> > > > +#include "../../include/asm-generic/tables.h"
> > > > +#include "../../include/linux/stringify.h"
> > > > +
> > > >  #define EX_ENTRY_SIZE		12
> > > >  #define EX_ORIG_OFFSET		0
> > > >  #define EX_NEW_OFFSET		4
> > > > @@ -63,7 +67,9 @@ struct special_entry entries[] = {
> > > >  		.feature = ALT_FEATURE_OFFSET,
> > > >  	},
> > > >  	{
> > > > -		.sec = "__jump_table",
> > > > +		.sec = __stringify(SECTION_TBL(SECTION_DATA,
> > > > +				               __jump_table,
> > > > +					       SECTION_ORDER_ANY)),
> > > >  		.jump_or_nop = true,
> > > >  		.size = JUMP_ENTRY_SIZE,
> > > >  		.orig = JUMP_ORIG_OFFSET,
> > > 
> > > (continuing our discussion from another thread...)
> > > 
> > > I think tools code isn't allowed to include kernel files because the
> > > tools subdirectory is supposed to be completely independent.
> > 
> > That was also the case for userpsace tools in scripts/ -- for instance
> > scripts/mod/modpost.c made an exception. What I've proposed here to
> > keep things simple was to ensure -UKERNEL is passed and then only
> > include files we know will work.
> > 
> > Refer to the patch "kprobes: port .kprobes.text to section range"
> > in this series for an extension of the scripts/mod/modpost.c kernel
> > headers use.
> 
> I think the rule of separating code is stricter for tools/ than it is
> for scripts/.  The scripts are generally kernel-specific whereas the
> tools are independent.  I believe the goal is to be able to copy them
> out of the kernel tree and still be able to compile them.

I see.

> > > As far as I can tell, the section name will always be
> > > ".data.tbl.__jump_table.any".  Is that true?  If so, any reason why we
> > > can't just hard-code the string here?
> > 
> > Its a fair strategy, however if upstream changes the order name we'd
> > have to hand code this as well, by using a macro we keep it all in one
> > place.
> 
> Hm, do you expect the section name to change often?

Nope, if anything only upon deployment on major distributions due to
some perhaps compatibility thing with custom hacks folks may have carried
and this just ended up clashing with. The only other case I can think
of a need for a change would be if upstream linkers supported something
similar for another brand of section names, with the added gain that
we would then not even need the 2 new lines on the kernel linker script
for section ranges and tables per section.

> > > As you saw, if the string
> > > changes, objtool will complain and 0-day will report it.
> > 
> > Indeed, which is why I was hoping to instead stick to a standard
> > sections set of header files that lets us get these in on place.
> 
> Actually, I meant that obtool reporting the change would be a good
> thing, in favor of just hard-coding the string.  It lets objtool do its
> job of letting us know when something changes, like it did today.

Getting a report so you can fix something is one reason to have a tool,
having it so you can inspect changes is another. So it depends what uses
there are for objtool. I take it that for this case we do want upstream
objtool to embrace the new section name to avoid further reports as
issues ?

> > The only place I hand coded in this series was in the perl
> > file scripts/recordmcount.pl but I suppose if we wanted to get
> > creative we could even generate a header for it too.
> > 
> > If we want to avoid all this hacker include stuff another option
> > is to *generate* each respective sections.h for the kernel, and
> > also, one for tools, and one for perl. What do you think?
> 
> If the generated files aren't checked into git, tools/ will rely on
> kernel files and will no longer be independent.  If they *are* checked
> in, then we have to keep the files in sync.  Either way it sounds like
> overkill, just to avoid hard-coding a string for which objtool will
> already warn if it changes.

We can open code the string, that's fine. In retrospect since things
won't change often that keeps things simple.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 10/13] jump_label: port __jump_table to linker tables
@ 2016-07-27 22:55           ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-27 22:55 UTC (permalink / raw)
  To: Josh Poimboeuf
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker, xen-devel, ak,
	pali.rohar, dvhart, platform-driver-x86, mmarek, linux, jkosina,
	korea.drzix, linux-kbuild, tony.luck, akpm, linux-ia64,
	linux-arm-kernel, linux-sh, sparclinux, catalin.marinas,
	will.deacon, rostedt

On Fri, Jul 22, 2016 at 05:55:35PM -0500, Josh Poimboeuf wrote:
> On Sat, Jul 23, 2016 at 12:26:54AM +0200, Luis R. Rodriguez wrote:
> > On Fri, Jul 22, 2016 at 04:49:45PM -0500, Josh Poimboeuf wrote:
> > > On Fri, Jul 22, 2016 at 02:24:44PM -0700, Luis R. Rodriguez wrote:
> > > > diff --git a/tools/objtool/special.c b/tools/objtool/special.c
> > > > index bff8abb3a4aa..f0ad369f994b 100644
> > > > --- a/tools/objtool/special.c
> > > > +++ b/tools/objtool/special.c
> > > > @@ -26,6 +26,10 @@
> > > >  #include "special.h"
> > > >  #include "warn.h"
> > > >  
> > > > +#include "../../include/asm-generic/sections.h"
> > > > +#include "../../include/asm-generic/tables.h"
> > > > +#include "../../include/linux/stringify.h"
> > > > +
> > > >  #define EX_ENTRY_SIZE		12
> > > >  #define EX_ORIG_OFFSET		0
> > > >  #define EX_NEW_OFFSET		4
> > > > @@ -63,7 +67,9 @@ struct special_entry entries[] = {
> > > >  		.feature = ALT_FEATURE_OFFSET,
> > > >  	},
> > > >  	{
> > > > -		.sec = "__jump_table",
> > > > +		.sec = __stringify(SECTION_TBL(SECTION_DATA,
> > > > +				               __jump_table,
> > > > +					       SECTION_ORDER_ANY)),
> > > >  		.jump_or_nop = true,
> > > >  		.size = JUMP_ENTRY_SIZE,
> > > >  		.orig = JUMP_ORIG_OFFSET,
> > > 
> > > (continuing our discussion from another thread...)
> > > 
> > > I think tools code isn't allowed to include kernel files because the
> > > tools subdirectory is supposed to be completely independent.
> > 
> > That was also the case for userpsace tools in scripts/ -- for instance
> > scripts/mod/modpost.c made an exception. What I've proposed here to
> > keep things simple was to ensure -UKERNEL is passed and then only
> > include files we know will work.
> > 
> > Refer to the patch "kprobes: port .kprobes.text to section range"
> > in this series for an extension of the scripts/mod/modpost.c kernel
> > headers use.
> 
> I think the rule of separating code is stricter for tools/ than it is
> for scripts/.  The scripts are generally kernel-specific whereas the
> tools are independent.  I believe the goal is to be able to copy them
> out of the kernel tree and still be able to compile them.

I see.

> > > As far as I can tell, the section name will always be
> > > ".data.tbl.__jump_table.any".  Is that true?  If so, any reason why we
> > > can't just hard-code the string here?
> > 
> > Its a fair strategy, however if upstream changes the order name we'd
> > have to hand code this as well, by using a macro we keep it all in one
> > place.
> 
> Hm, do you expect the section name to change often?

Nope, if anything only upon deployment on major distributions due to
some perhaps compatibility thing with custom hacks folks may have carried
and this just ended up clashing with. The only other case I can think
of a need for a change would be if upstream linkers supported something
similar for another brand of section names, with the added gain that
we would then not even need the 2 new lines on the kernel linker script
for section ranges and tables per section.

> > > As you saw, if the string
> > > changes, objtool will complain and 0-day will report it.
> > 
> > Indeed, which is why I was hoping to instead stick to a standard
> > sections set of header files that lets us get these in on place.
> 
> Actually, I meant that obtool reporting the change would be a good
> thing, in favor of just hard-coding the string.  It lets objtool do its
> job of letting us know when something changes, like it did today.

Getting a report so you can fix something is one reason to have a tool,
having it so you can inspect changes is another. So it depends what uses
there are for objtool. I take it that for this case we do want upstream
objtool to embrace the new section name to avoid further reports as
issues ?

> > The only place I hand coded in this series was in the perl
> > file scripts/recordmcount.pl but I suppose if we wanted to get
> > creative we could even generate a header for it too.
> > 
> > If we want to avoid all this hacker include stuff another option
> > is to *generate* each respective sections.h for the kernel, and
> > also, one for tools, and one for perl. What do you think?
> 
> If the generated files aren't checked into git, tools/ will rely on
> kernel files and will no longer be independent.  If they *are* checked
> in, then we have to keep the files in sync.  Either way it sounds like
> overkill, just to avoid hard-coding a string for which objtool will
> already warn if it changes.

We can open code the string, that's fine. In retrospect since things
won't change often that keeps things simple.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 13/13] kprobes: port blacklist kprobes to linker table
  2016-07-25 15:27     ` Masami Hiramatsu
  (?)
@ 2016-07-27 23:00       ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-27 23:00 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko

On Tue, Jul 26, 2016 at 12:27:22AM +0900, Masami Hiramatsu wrote:
> On Fri, 22 Jul 2016 14:24:47 -0700
> "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
> 
> > 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:
> 
> This is OK for me, and if you would like to make sure, please use ftrace to probe
>  (easier  than making new module) and compare debugfs/blacklist which shows
> all blacklisted functions, so if all the function names are same it
> must be OK :).

Ah I see, sure thanks for the tip! I was actually hoping to write a unit
test that automates this testing, but that can be done and submitted later,
the approach you suggest should make writing a unit easier as well.

> Acked-by: Masami Hiramatsu <mhiramat@kernel.org>

Great, thanks,

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 13/13] kprobes: port blacklist kprobes to linker table
@ 2016-07-27 23:00       ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-27 23:00 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko

On Tue, Jul 26, 2016 at 12:27:22AM +0900, Masami Hiramatsu wrote:
> On Fri, 22 Jul 2016 14:24:47 -0700
> "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
> 
> > 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:
> 
> This is OK for me, and if you would like to make sure, please use ftrace to probe
>  (easier  than making new module) and compare debugfs/blacklist which shows
> all blacklisted functions, so if all the function names are same it
> must be OK :).

Ah I see, sure thanks for the tip! I was actually hoping to write a unit
test that automates this testing, but that can be done and submitted later,
the approach you suggest should make writing a unit easier as well.

> Acked-by: Masami Hiramatsu <mhiramat@kernel.org>

Great, thanks,

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 13/13] kprobes: port blacklist kprobes to linker table
@ 2016-07-27 23:00       ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-27 23:00 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker, xen-devel, ak,
	pali.rohar, dvhart, platform-driver-x86, mmarek, linux, jkosina,
	korea.drzix, linux-kbuild, tony.luck, akpm, linux-ia64,
	linux-arm-kernel, linux-sh, sparclinux, catalin.marinas,
	will.deacon, rostedt, jpoimboe

On Tue, Jul 26, 2016 at 12:27:22AM +0900, Masami Hiramatsu wrote:
> On Fri, 22 Jul 2016 14:24:47 -0700
> "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
> 
> > 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:
> 
> This is OK for me, and if you would like to make sure, please use ftrace to probe
>  (easier  than making new module) and compare debugfs/blacklist which shows
> all blacklisted functions, so if all the function names are same it
> must be OK :).

Ah I see, sure thanks for the tip! I was actually hoping to write a unit
test that automates this testing, but that can be done and submitted later,
the approach you suggest should make writing a unit easier as well.

> Acked-by: Masami Hiramatsu <mhiramat@kernel.org>

Great, thanks,

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-07-25 15:30     ` Masami Hiramatsu
  (?)
@ 2016-07-27 23:02       ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-27 23:02 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko

On Tue, Jul 26, 2016 at 12:30:14AM +0900, Masami Hiramatsu wrote:
> On Fri, 22 Jul 2016 14:24:41 -0700
> "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
> 
> > +/**
> > + * LINKTABLE_RUN_ALL - iterate and run through all entries on a linker table
> > + *
> > + * @tbl: linker table
> > + * @func: structure name for the function name we want to call.
> > + * @args...: arguments to pass to func
> > + *
> > + * Example usage:
> > + *
> > + *   LINKTABLE_RUN_ALL(frobnicator_fns, some_run,);
> > + */
> > +#define LINKTABLE_RUN_ALL(tbl, func, args...)				\
> > +do {									\
> > +	size_t i;							\
> > +	for (i = 0; i < LINUX_SECTION_SIZE(tbl); i++)			\
> > +		(tbl[i]).func (args);					\
> > +} while (0);
> > +
> > +/**
> > + * LINKTABLE_RUN_ERR - run each linker table entry func and return error if any
> > + *
> > + * @tbl: linker table
> > + * @func: structure name for the function name we want to call.
> > + * @args...: arguments to pass to func
> > + *
> > + * Example usage:
> > + *
> > + *   unsigned int err = LINKTABLE_RUN_ERR(frobnicator_fns, some_run,);
> > + */
> > +#define LINKTABLE_RUN_ERR(tbl, func, args...)				\
> > +({									\
> > +	size_t i;							\
> > +	int err = 0;							\
> > +	for (i = 0; !err && i < LINUX_SECTION_SIZE(tbl); i++)		\
> > +		err = (tbl[i]).func (args);				\
> > +		err; \
> > +})
> 
> These iteration APIs are a bit dangerous, at least for these APIs we'd better change
> name like as FUNCTABLE_RUN etc. because LINKTABLE can contain not only function address
> but also some data (or address of data).

Sure will do, thanks for the review.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-07-27 23:02       ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-27 23:02 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko

On Tue, Jul 26, 2016 at 12:30:14AM +0900, Masami Hiramatsu wrote:
> On Fri, 22 Jul 2016 14:24:41 -0700
> "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
> 
> > +/**
> > + * LINKTABLE_RUN_ALL - iterate and run through all entries on a linker table
> > + *
> > + * @tbl: linker table
> > + * @func: structure name for the function name we want to call.
> > + * @args...: arguments to pass to func
> > + *
> > + * Example usage:
> > + *
> > + *   LINKTABLE_RUN_ALL(frobnicator_fns, some_run,);
> > + */
> > +#define LINKTABLE_RUN_ALL(tbl, func, args...)				\
> > +do {									\
> > +	size_t i;							\
> > +	for (i = 0; i < LINUX_SECTION_SIZE(tbl); i++)			\
> > +		(tbl[i]).func (args);					\
> > +} while (0);
> > +
> > +/**
> > + * LINKTABLE_RUN_ERR - run each linker table entry func and return error if any
> > + *
> > + * @tbl: linker table
> > + * @func: structure name for the function name we want to call.
> > + * @args...: arguments to pass to func
> > + *
> > + * Example usage:
> > + *
> > + *   unsigned int err = LINKTABLE_RUN_ERR(frobnicator_fns, some_run,);
> > + */
> > +#define LINKTABLE_RUN_ERR(tbl, func, args...)				\
> > +({									\
> > +	size_t i;							\
> > +	int err = 0;							\
> > +	for (i = 0; !err && i < LINUX_SECTION_SIZE(tbl); i++)		\
> > +		err = (tbl[i]).func (args);				\
> > +		err; \
> > +})
> 
> These iteration APIs are a bit dangerous, at least for these APIs we'd better change
> name like as FUNCTABLE_RUN etc. because LINKTABLE can contain not only function address
> but also some data (or address of data).

Sure will do, thanks for the review.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-07-27 23:02       ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-07-27 23:02 UTC (permalink / raw)
  To: Masami Hiramatsu
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker, xen-devel, ak,
	pali.rohar, dvhart, platform-driver-x86, mmarek, linux, jkosina,
	korea.drzix, linux-kbuild, tony.luck, akpm, linux-ia64,
	linux-arm-kernel, linux-sh, sparclinux, catalin.marinas,
	will.deacon, rostedt, jpoimboe

On Tue, Jul 26, 2016 at 12:30:14AM +0900, Masami Hiramatsu wrote:
> On Fri, 22 Jul 2016 14:24:41 -0700
> "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
> 
> > +/**
> > + * LINKTABLE_RUN_ALL - iterate and run through all entries on a linker table
> > + *
> > + * @tbl: linker table
> > + * @func: structure name for the function name we want to call.
> > + * @args...: arguments to pass to func
> > + *
> > + * Example usage:
> > + *
> > + *   LINKTABLE_RUN_ALL(frobnicator_fns, some_run,);
> > + */
> > +#define LINKTABLE_RUN_ALL(tbl, func, args...)				\
> > +do {									\
> > +	size_t i;							\
> > +	for (i = 0; i < LINUX_SECTION_SIZE(tbl); i++)			\
> > +		(tbl[i]).func (args);					\
> > +} while (0);
> > +
> > +/**
> > + * LINKTABLE_RUN_ERR - run each linker table entry func and return error if any
> > + *
> > + * @tbl: linker table
> > + * @func: structure name for the function name we want to call.
> > + * @args...: arguments to pass to func
> > + *
> > + * Example usage:
> > + *
> > + *   unsigned int err = LINKTABLE_RUN_ERR(frobnicator_fns, some_run,);
> > + */
> > +#define LINKTABLE_RUN_ERR(tbl, func, args...)				\
> > +({									\
> > +	size_t i;							\
> > +	int err = 0;							\
> > +	for (i = 0; !err && i < LINUX_SECTION_SIZE(tbl); i++)		\
> > +		err = (tbl[i]).func (args);				\
> > +		err; \
> > +})
> 
> These iteration APIs are a bit dangerous, at least for these APIs we'd better change
> name like as FUNCTABLE_RUN etc. because LINKTABLE can contain not only function address
> but also some data (or address of data).

Sure will do, thanks for the review.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-07-27 23:02       ` Luis R. Rodriguez
@ 2016-07-28 17:08         ` H. Peter Anvin
  -1 siblings, 0 replies; 176+ messages in thread
From: H. Peter Anvin @ 2016-07-28 17:08 UTC (permalink / raw)
  To: Luis R. Rodriguez, Masami Hiramatsu

tglx@linutronix.de,mingo@redhat.com,bp@alien8.de,linux@arm.linux.org.uk,masami.hiramatsu.pt@hitachi.com,jbaron@akamai.com,heiko.carstens@de.ibm.com,ananth@linux.vnet.ibm.com,anil.s.keshavamurthy@intel.com,davem@davemloft.net,realmz6@gmail.com,x86@kernel.org,luto@amacapital.net,keescook@chromium.org,torvalds@linux-foundation.org,gregkh@linuxfoundation.org,rusty@rustcorp.com.au,gnomes@lxorguk.ukuu.org.uk,alan@linux.intel.com,dwmw2@infradead.org,arnd@arndb.de,ming.lei@canonical.com,linux-arch@vger.kernel.org,benh@kernel.crashing.org,ananth@in.ibm.com,pebolle@tiscali.nl,fontana@sharpeleven.org,ciaran.farrell@suse.com,christopher.denicolo@suse.com,david.vrabel@citrix.com,konrad.wilk@oracle.com,mcb30@ipxe.org,jgross@suse.com,andrew.cooper3@citrix.com,andriy.shevchenko@linux.intel.com,paul.gortmaker@windriver.com,xen-devel@lists.xensource.com,ak@linux.intel.com,pali.rohar@gmail.com,dvhart@infradead.org,platform-driver-x86@vger.kernel.org,mmarek@suse.com,linux@rasmusvillemoes.dk,jko!
 sina@suse
.cz,korea.drzix@gmail.com,linux-kbuild@vger.kernel.org,tony.luck@intel.com,akpm@linux-foundation.org,linux-ia64@vger.kernel.org,linux-arm-kernel@lists.infradead.org,linux-sh@vger.kernel.org,sparclinux@vger.kernel.org,catalin.marinas@arm.com,will.deacon@arm.com,rostedt@goodmis.org,jpoimboe@redhat.com
Message-ID: <01FD20B1-E788-4CC6-81CF-BA26F000FFCB@zytor.com>

On July 27, 2016 4:02:18 PM PDT, "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
>On Tue, Jul 26, 2016 at 12:30:14AM +0900, Masami Hiramatsu wrote:
>> On Fri, 22 Jul 2016 14:24:41 -0700
>> "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
>> 
>> > +/**
>> > + * LINKTABLE_RUN_ALL - iterate and run through all entries on a
>linker table
>> > + *
>> > + * @tbl: linker table
>> > + * @func: structure name for the function name we want to call.
>> > + * @args...: arguments to pass to func
>> > + *
>> > + * Example usage:
>> > + *
>> > + *   LINKTABLE_RUN_ALL(frobnicator_fns, some_run,);
>> > + */
>> > +#define LINKTABLE_RUN_ALL(tbl, func, args...)				\
>> > +do {									\
>> > +	size_t i;							\
>> > +	for (i = 0; i < LINUX_SECTION_SIZE(tbl); i++)			\
>> > +		(tbl[i]).func (args);					\
>> > +} while (0);
>> > +
>> > +/**
>> > + * LINKTABLE_RUN_ERR - run each linker table entry func and return
>error if any
>> > + *
>> > + * @tbl: linker table
>> > + * @func: structure name for the function name we want to call.
>> > + * @args...: arguments to pass to func
>> > + *
>> > + * Example usage:
>> > + *
>> > + *   unsigned int err = LINKTABLE_RUN_ERR(frobnicator_fns,
>some_run,);
>> > + */
>> > +#define LINKTABLE_RUN_ERR(tbl, func, args...)				\
>> > +({									\
>> > +	size_t i;							\
>> > +	int err = 0;							\
>> > +	for (i = 0; !err && i < LINUX_SECTION_SIZE(tbl); i++)		\
>> > +		err = (tbl[i]).func (args);				\
>> > +		err; \
>> > +})
>> 
>> These iteration APIs are a bit dangerous, at least for these APIs
>we'd better change
>> name like as FUNCTABLE_RUN etc. because LINKTABLE can contain not
>only function address
>> but also some data (or address of data).
>
>Sure will do, thanks for the review.
>
>  Luis

I don't know if they are dangerous.  Keep in mind C type checking is still present.
-- 
Sent from my Android device with K-9 Mail. Please excuse brevity and formatting.

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-07-27 23:02       ` Luis R. Rodriguez
  (?)
  (?)
@ 2016-07-28 17:08       ` H. Peter Anvin
  -1 siblings, 0 replies; 176+ messages in thread
From: H. Peter Anvin @ 2016-07-28 17:08 UTC (permalink / raw)
  To: Luis R. Rodriguez, Masami Hiramatsu

tglx@linutronix.de,mingo@redhat.com,bp@alien8.de,linux@arm.linux.org.uk,masami.hiramatsu.pt@hitachi.com,jbaron@akamai.com,heiko.carstens@de.ibm.com,ananth@linux.vnet.ibm.com,anil.s.keshavamurthy@intel.com,davem@davemloft.net,realmz6@gmail.com,x86@kernel.org,luto@amacapital.net,keescook@chromium.org,torvalds@linux-foundation.org,gregkh@linuxfoundation.org,rusty@rustcorp.com.au,gnomes@lxorguk.ukuu.org.uk,alan@linux.intel.com,dwmw2@infradead.org,arnd@arndb.de,ming.lei@canonical.com,linux-arch@vger.kernel.org,benh@kernel.crashing.org,ananth@in.ibm.com,pebolle@tiscali.nl,fontana@sharpeleven.org,ciaran.farrell@suse.com,christopher.denicolo@suse.com,david.vrabel@citrix.com,konrad.wilk@oracle.com,mcb30@ipxe.org,jgross@suse.com,andrew.cooper3@citrix.com,andriy.shevchenko@linux.intel.com,paul.gortma
 ker@windriver.com,xen-devel@lists.xensource.com,ak@linux.intel.com,pali.rohar@gmail.com,dvhart@infradead.org,platform-driver-x86@vger.kernel.org,mmarek@suse.com,linux@rasmusvillemoes.dk,jko!
 sina@suse
.cz,korea.drzix@gmail.com,linux-kbuild@vger.kernel.org,tony.luck@intel.com,akpm@linux-foundation.org,linux-ia64@vger.kernel.org,linux-arm-kernel@lists.infradead.org,linux-sh@vger.kernel.org,sparclinux@vger.kernel.org,catalin.marinas@arm.com,will.deacon@arm.com,rostedt@goodmis.org,jpoimboe@redhat.com
Message-ID: <01FD20B1-E788-4CC6-81CF-BA26F000FFCB@zytor.com>

On July 27, 2016 4:02:18 PM PDT, "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
>On Tue, Jul 26, 2016 at 12:30:14AM +0900, Masami Hiramatsu wrote:
>> On Fri, 22 Jul 2016 14:24:41 -0700
>> "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
>> 
>> > +/**
>> > + * LINKTABLE_RUN_ALL - iterate and run through all entries on a
>linker table
>> > + *
>> > + * @tbl: linker table
>> > + * @func: structure name for the function name we want to call.
>> > + * @args...: arguments to pass to func
>> > + *
>> > + * Example usage:
>> > + *
>> > + *   LINKTABLE_RUN_ALL(frobnicator_fns, some_run,);
>> > + */
>> > +#define LINKTABLE_RUN_ALL(tbl, func, args...)				\
>> > +do {									\
>> > +	size_t i;							\
>> > +	for (i = 0; i < LINUX_SECTION_SIZE(tbl); i++)			\
>> > +		(tbl[i]).func (args);					\
>> > +} while (0);
>> > +
>> > +/**
>> > + * LINKTABLE_RUN_ERR - run each linker table entry func and return
>error if any
>> > + *
>> > + * @tbl: linker table
>> > + * @func: structure name for the function name we want to call.
>> > + * @args...: arguments to pass to func
>> > + *
>> > + * Example usage:
>> > + *
>> > + *   unsigned int err = LINKTABLE_RUN_ERR(frobnicator_fns,
>some_run,);
>> > + */
>> > +#define LINKTABLE_RUN_ERR(tbl, func, args...)				\
>> > +({									\
>> > +	size_t i;							\
>> > +	int err = 0;							\
>> > +	for (i = 0; !err && i < LINUX_SECTION_SIZE(tbl); i++)		\
>> > +		err = (tbl[i]).func (args);				\
>> > +		err; \
>> > +})
>> 
>> These iteration APIs are a bit dangerous, at least for these APIs
>we'd better change
>> name like as FUNCTABLE_RUN etc. because LINKTABLE can contain not
>only function address
>> but also some data (or address of data).
>
>Sure will do, thanks for the review.
>
>  Luis

I don't know if they are dangerous.  Keep in mind C type checking is still present.
-- 
Sent from my Android device with K-9 Mail. Please excuse brevity and formatting.

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-07-28 17:08         ` H. Peter Anvin
  0 siblings, 0 replies; 176+ messages in thread
From: H. Peter Anvin @ 2016-07-28 17:08 UTC (permalink / raw)
  To: Luis R. Rodriguez, Masami Hiramatsu

tglx@linutronix.de,mingo@redhat.com,bp@alien8.de,linux@arm.linux.org.uk,masami.hiramatsu.pt@hitachi.com,jbaron@akamai.com,heiko.carstens@de.ibm.com,ananth@linux.vnet.ibm.com,anil.s.keshavamurthy@intel.com,davem@davemloft.net,realmz6@gmail.com,x86@kernel.org,luto@amacapital.net,keescook@chromium.org,torvalds@linux-foundation.org,gregkh@linuxfoundation.org,rusty@rustcorp.com.au,gnomes@lxorguk.ukuu.org.uk,alan@linux.intel.com,dwmw2@infradead.org,arnd@arndb.de,ming.lei@canonical.com,linux-arch@vger.kernel.org,benh@kernel.crashing.org,ananth@in.ibm.com,pebolle@tiscali.nl,fontana@sharpeleven.org,ciaran.farrell@suse.com,christopher.denicolo@suse.com,david.vrabel@citrix.com,konrad.wilk@oracle.com,mcb30@ipxe.org,jgross@suse.com,andrew.cooper3@citrix.com,andriy.shevchenko@linux.intel.com,paul.gortmaker@windriver.com,xen-devel@lists.xensource.com,ak@linux.intel.com,pali.rohar@gmail.com,dvhart@infradead.org,platform-driver-x86@vger.kernel.org,mmarek@suse.com,linux@rasmusvillemoes.dk,jko!
 sina@suse
.cz,korea.drzix@gmail.com,linux-kbuild@vger.kernel.org,tony.luck@intel.com,akpm@linux-foundation.org,linux-ia64@vger.kernel.org,linux-arm-kernel@lists.infradead.org,linux-sh@vger.kernel.org,sparclinux@vger.kernel.org,catalin.marinas@arm.com,will.deacon@arm.com,rostedt@goodmis.org,jpoimboe@redhat.com
Message-ID: <01FD20B1-E788-4CC6-81CF-BA26F000FFCB@zytor.com>

On July 27, 2016 4:02:18 PM PDT, "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
>On Tue, Jul 26, 2016 at 12:30:14AM +0900, Masami Hiramatsu wrote:
>> On Fri, 22 Jul 2016 14:24:41 -0700
>> "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
>> 
>> > +/**
>> > + * LINKTABLE_RUN_ALL - iterate and run through all entries on a
>linker table
>> > + *
>> > + * @tbl: linker table
>> > + * @func: structure name for the function name we want to call.
>> > + * @args...: arguments to pass to func
>> > + *
>> > + * Example usage:
>> > + *
>> > + *   LINKTABLE_RUN_ALL(frobnicator_fns, some_run,);
>> > + */
>> > +#define LINKTABLE_RUN_ALL(tbl, func, args...)				\
>> > +do {									\
>> > +	size_t i;							\
>> > +	for (i = 0; i < LINUX_SECTION_SIZE(tbl); i++)			\
>> > +		(tbl[i]).func (args);					\
>> > +} while (0);
>> > +
>> > +/**
>> > + * LINKTABLE_RUN_ERR - run each linker table entry func and return
>error if any
>> > + *
>> > + * @tbl: linker table
>> > + * @func: structure name for the function name we want to call.
>> > + * @args...: arguments to pass to func
>> > + *
>> > + * Example usage:
>> > + *
>> > + *   unsigned int err = LINKTABLE_RUN_ERR(frobnicator_fns,
>some_run,);
>> > + */
>> > +#define LINKTABLE_RUN_ERR(tbl, func, args...)				\
>> > +({									\
>> > +	size_t i;							\
>> > +	int err = 0;							\
>> > +	for (i = 0; !err && i < LINUX_SECTION_SIZE(tbl); i++)		\
>> > +		err = (tbl[i]).func (args);				\
>> > +		err; \
>> > +})
>> 
>> These iteration APIs are a bit dangerous, at least for these APIs
>we'd better change
>> name like as FUNCTABLE_RUN etc. because LINKTABLE can contain not
>only function address
>> but also some data (or address of data).
>
>Sure will do, thanks for the review.
>
>  Luis

I don't know if they are dangerous.  Keep in mind C type checking is still present.
-- 
Sent from my Android device with K-9 Mail. Please excuse brevity and formatting.

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-07-27 23:02       ` Luis R. Rodriguez
                         ` (4 preceding siblings ...)
  (?)
@ 2016-07-28 17:08       ` H. Peter Anvin
  -1 siblings, 0 replies; 176+ messages in thread
From: H. Peter Anvin @ 2016-07-28 17:08 UTC (permalink / raw)
  To: Luis R. Rodriguez, Masami Hiramatsu

tglx@linutronix.de,mingo@redhat.com,bp@alien8.de,linux@arm.linux.org.uk,masami.hiramatsu.pt@hitachi.com,jbaron@akamai.com,heiko.carstens@de.ibm.com,ananth@linux.vnet.ibm.com,anil.s.keshavamurthy@intel.com,davem@davemloft.net,realmz6@gmail.com,x86@kernel.org,luto@amacapital.net,keescook@chromium.org,torvalds@linux-foundation.org,gregkh@linuxfoundation.org,rusty@rustcorp.com.au,gnomes@lxorguk.ukuu.org.uk,alan@linux.intel.com,dwmw2@infradead.org,arnd@arndb.de,ming.lei@canonical.com,linux-arch@vger.kernel.org,benh@kernel.crashing.org,ananth@in.ibm.com,pebolle@tiscali.nl,fontana@sharpeleven.org,ciaran.farrell@suse.com,christopher.denicolo@suse.com,david.vrabel@citrix.com,konrad.wilk@oracle.com,mcb30@ipxe.org,jgross@suse.com,andrew.cooper3@citrix.com,andriy.shevchenko@linux.intel.com,paul.gortma
 ker@windriver.com,xen-devel@lists.xensource.com,ak@linux.intel.com,pali.rohar@gmail.com,dvhart@infradead.org,platform-driver-x86@vger.kernel.org,mmarek@suse.com,linux@rasmusvillemoes.dk,jko!
 sina@suse
.cz,korea.drzix@gmail.com,linux-kbuild@vger.kernel.org,tony.luck@intel.com,akpm@linux-foundation.org,linux-ia64@vger.kernel.org,linux-arm-kernel@lists.infradead.org,linux-sh@vger.kernel.org,sparclinux@vger.kernel.org,catalin.marinas@arm.com,will.deacon@arm.com,rostedt@goodmis.org,jpoimboe@redhat.com
Message-ID: <01FD20B1-E788-4CC6-81CF-BA26F000FFCB@zytor.com>

On July 27, 2016 4:02:18 PM PDT, "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
>On Tue, Jul 26, 2016 at 12:30:14AM +0900, Masami Hiramatsu wrote:
>> On Fri, 22 Jul 2016 14:24:41 -0700
>> "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
>> 
>> > +/**
>> > + * LINKTABLE_RUN_ALL - iterate and run through all entries on a
>linker table
>> > + *
>> > + * @tbl: linker table
>> > + * @func: structure name for the function name we want to call.
>> > + * @args...: arguments to pass to func
>> > + *
>> > + * Example usage:
>> > + *
>> > + *   LINKTABLE_RUN_ALL(frobnicator_fns, some_run,);
>> > + */
>> > +#define LINKTABLE_RUN_ALL(tbl, func, args...)				\
>> > +do {									\
>> > +	size_t i;							\
>> > +	for (i = 0; i < LINUX_SECTION_SIZE(tbl); i++)			\
>> > +		(tbl[i]).func (args);					\
>> > +} while (0);
>> > +
>> > +/**
>> > + * LINKTABLE_RUN_ERR - run each linker table entry func and return
>error if any
>> > + *
>> > + * @tbl: linker table
>> > + * @func: structure name for the function name we want to call.
>> > + * @args...: arguments to pass to func
>> > + *
>> > + * Example usage:
>> > + *
>> > + *   unsigned int err = LINKTABLE_RUN_ERR(frobnicator_fns,
>some_run,);
>> > + */
>> > +#define LINKTABLE_RUN_ERR(tbl, func, args...)				\
>> > +({									\
>> > +	size_t i;							\
>> > +	int err = 0;							\
>> > +	for (i = 0; !err && i < LINUX_SECTION_SIZE(tbl); i++)		\
>> > +		err = (tbl[i]).func (args);				\
>> > +		err; \
>> > +})
>> 
>> These iteration APIs are a bit dangerous, at least for these APIs
>we'd better change
>> name like as FUNCTABLE_RUN etc. because LINKTABLE can contain not
>only function address
>> but also some data (or address of data).
>
>Sure will do, thanks for the review.
>
>  Luis

I don't know if they are dangerous.  Keep in mind C type checking is still present.
-- 
Sent from my Android device with K-9 Mail. Please excuse brevity and formatting.

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-07-27 23:02       ` Luis R. Rodriguez
                         ` (2 preceding siblings ...)
  (?)
@ 2016-07-28 17:08       ` H. Peter Anvin
  -1 siblings, 0 replies; 176+ messages in thread
From: H. Peter Anvin @ 2016-07-28 17:08 UTC (permalink / raw)
  To: Luis R. Rodriguez, Masami Hiramatsu

tglx@linutronix.de,mingo@redhat.com,bp@alien8.de,linux@arm.linux.org.uk,masami.hiramatsu.pt@hitachi.com,jbaron@akamai.com,heiko.carstens@de.ibm.com,ananth@linux.vnet.ibm.com,anil.s.keshavamurthy@intel.com,davem@davemloft.net,realmz6@gmail.com,x86@kernel.org,luto@amacapital.net,keescook@chromium.org,torvalds@linux-foundation.org,gregkh@linuxfoundation.org,rusty@rustcorp.com.au,gnomes@lxorguk.ukuu.org.uk,alan@linux.intel.com,dwmw2@infradead.org,arnd@arndb.de,ming.lei@canonical.com,linux-arch@vger.kernel.org,benh@kernel.crashing.org,ananth@in.ibm.com,pebolle@tiscali.nl,fontana@sharpeleven.org,ciaran.farrell@suse.com,christopher.denicolo@suse.com,david.vrabel@citrix.com,konrad.wilk@oracle.com,mcb30@ipxe.org,jgross@suse.com,andrew.cooper3@citrix.com,andriy.shevchenko@linux.intel.com,paul.gortmaker@windriver.com,xen-devel@lists.xensource.com,ak@linux.intel.com,pali.rohar@gmail.com,dvhart@infradead.org,platform-driver-x86@vger.kernel.org,mmarek@suse.com,linux@rasmusvillemoes.dk,jko!
 sina@suse
.cz,korea.drzix@gmail.com,linux-kbuild@vger.kernel.org,tony.luck@intel.com,akpm@linux-foundation.org,linux-ia64@vger.kernel.org,linux-arm-kernel@lists.infradead.org,linux-sh@vger.kernel.org,sparclinux@vger.kernel.org,catalin.marinas@arm.com,will.deacon@arm.com,rostedt@goodmis.org,jpoimboe@redhat.com
Message-ID: <01FD20B1-E788-4CC6-81CF-BA26F000FFCB@zytor.com>

On July 27, 2016 4:02:18 PM PDT, "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
>On Tue, Jul 26, 2016 at 12:30:14AM +0900, Masami Hiramatsu wrote:
>> On Fri, 22 Jul 2016 14:24:41 -0700
>> "Luis R. Rodriguez" <mcgrof@kernel.org> wrote:
>> 
>> > +/**
>> > + * LINKTABLE_RUN_ALL - iterate and run through all entries on a
>linker table
>> > + *
>> > + * @tbl: linker table
>> > + * @func: structure name for the function name we want to call.
>> > + * @args...: arguments to pass to func
>> > + *
>> > + * Example usage:
>> > + *
>> > + *   LINKTABLE_RUN_ALL(frobnicator_fns, some_run,);
>> > + */
>> > +#define LINKTABLE_RUN_ALL(tbl, func, args...)				\
>> > +do {									\
>> > +	size_t i;							\
>> > +	for (i = 0; i < LINUX_SECTION_SIZE(tbl); i++)			\
>> > +		(tbl[i]).func (args);					\
>> > +} while (0);
>> > +
>> > +/**
>> > + * LINKTABLE_RUN_ERR - run each linker table entry func and return
>error if any
>> > + *
>> > + * @tbl: linker table
>> > + * @func: structure name for the function name we want to call.
>> > + * @args...: arguments to pass to func
>> > + *
>> > + * Example usage:
>> > + *
>> > + *   unsigned int err = LINKTABLE_RUN_ERR(frobnicator_fns,
>some_run,);
>> > + */
>> > +#define LINKTABLE_RUN_ERR(tbl, func, args...)				\
>> > +({									\
>> > +	size_t i;							\
>> > +	int err = 0;							\
>> > +	for (i = 0; !err && i < LINUX_SECTION_SIZE(tbl); i++)		\
>> > +		err = (tbl[i]).func (args);				\
>> > +		err; \
>> > +})
>> 
>> These iteration APIs are a bit dangerous, at least for these APIs
>we'd better change
>> name like as FUNCTABLE_RUN etc. because LINKTABLE can contain not
>only function address
>> but also some data (or address of data).
>
>Sure will do, thanks for the review.
>
>  Luis

I don't know if they are dangerous.  Keep in mind C type checking is still present.
-- 
Sent from my Android device with K-9 Mail. Please excuse brevity and formatting.

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-07-22 21:24   ` Luis R. Rodriguez
  (?)
@ 2016-07-29 10:06     ` Borislav Petkov
  -1 siblings, 0 replies; 176+ messages in thread
From: Borislav Petkov @ 2016-07-29 10:06 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, linux, mhiramat, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-

On Fri, Jul 22, 2016 at 02:24:41PM -0700, Luis R. Rodriguez wrote:
> 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
> originally based on Michael Brown's iPXE's linker table solution but
> has been significantly modified to fit Linux's use in its integration.

...

> diff --git a/include/asm-generic/tables.h b/include/asm-generic/tables.h
> new file mode 100644
> index 000000000000..5cf655590a19
> --- /dev/null
> +++ b/include/asm-generic/tables.h
> @@ -0,0 +1,70 @@
> +#ifndef _ASM_GENERIC_TABLES_H_
> +#define _ASM_GENERIC_TABLES_H_
> +/*
> + * Linux linker tables
> + *
> + * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
> + *
> + * 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/.
> + */
> +
> +#ifdef __KERNEL__
> +# include <asm/sections.h>
> +#endif /* __KERNEL__ */
> +
> +#define SECTION_TYPE_TABLES	tbl

What is that for? Section type? Do we have more types or is it useless
and can go?

> +
> +#define SECTION_TBL(section, name, level)				\
> +	SECTION_TYPE(section, SECTION_TYPE_TABLES, name, level)
> +
> +#define SECTION_TBL_ALL(section)					\
> +	SECTION_TYPE_ALL(section,SECTION_TYPE_TABLES)
> +
> +#ifndef section_tbl
> +# define section_tbl(section, name, level, flags)			\
> +	 section_type(section, SECTION_TYPE_TABLES, name,		\
> +		     level, flags)

That section_type macro is actually saying the following code should
be in it. Can we make its name have a verb, i.e., something like
"set_section" to make it more clear?

Also, that type SECTION_TYPE_TABLES looks redundant to me but it
might start making more sense after I've gone through the rest of the
series...

> +#endif
> +
> +#ifndef section_tbl_any
> +# define section_tbl_any(section, name, flags)				\
> +	 section_type(section, SECTION_TYPE_TABLES, name,		\
> +		     SECTION_ORDER_ANY, flags)
> +#endif
> +
> +#ifndef section_tbl_asmtype
> +# define section_tbl_asmtype(section, name, level, flags, asmtype)	\

And here's the confusion: there's "asmtype" but there's also
SECTION_TYPE_TABLES.

That asmtype is the *actual* section type in gas speak, i.e., @progbits,
@note, etc.

Now *that* should be your type. The SECTION_TYPE_TABLES should be called
something else or completely gone.

> +	 section_type_asmtype(section, SECTION_TYPE_TABLES, name,	\
> +			     level, flags, asmtype)
> +#endif
> +
> +#ifndef push_section_tbl
> +# define push_section_tbl(section, name, level, flags)			\
> +	 push_section_type(section, SECTION_TYPE_TABLES, name,		\
> +			  level, flags)
> +#endif
> +
> +#ifndef push_section_tbl_any
> +# define push_section_tbl_any(section, name, flags)			\
> +	 push_section_type(section, SECTION_TYPE_TABLES, name,		\
> +			  SECTION_ORDER_ANY, flags)
> +#endif
> +
> +#if defined(__ASSEMBLER__) || defined(__ASSEMBLY__)
> +
> +# ifndef DECLARE_SECTION_TBL
> +#  define DECLARE_SECTION_TBL(section, name)				\
> +  push_section_tbl(section, name,,) ;					\
> +  .globl name ;								\
> +name: ;									\
> +  .popsection								\
> +									\
> +  push_section_tbl(section, name, ~,) ;					\
> +  .popsection
> +# endif

#endif /* DECLARE_SECTION_TBL */

Btw, what does that macro do? I don't see it used anywhere.

> +
> +#endif /* defined(__ASSEMBLER__) || defined(__ASSEMBLY__) */
> +
> +#endif /* _ASM_GENERIC_TABLES_H_ */


...


> diff --git a/include/linux/tables.h b/include/linux/tables.h
> new file mode 100644
> index 000000000000..89d46f4c5739
> --- /dev/null
> +++ b/include/linux/tables.h
> @@ -0,0 +1,597 @@
> +#ifndef _LINUX_LINKER_TABLES_H
> +#define _LINUX_LINKER_TABLES_H
> +/*
> + * Linux linker tables
> + *
> + * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
> + *
> + * 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 <linux/sections.h>
> +#ifdef __KERNEL__
> +# include <asm/tables.h>
> +#endif /* __KERNEL__ */
> +
> +#ifndef __ASSEMBLY__
> +
> +/**
> + * DOC: Introduction
> + *
> + * A linker table is a data structure that is stitched together from items
> + * in multiple object files. Linux has historically implicitly used linker

s/historically//

"for ages" already says "historically" :-)

> + * tables for ages, however they were all built in an adhoc manner which
> + * requires linker script modifications, per architecture. This linker table

s/,//

> + * solution provides a general linker table facility so that a new linker table
> + * can be implemented by changing C code only.
> + *
> + * Linker tables help you simplify init sequences by using ELF sections, linker
> + * build time selective sorting (disabled options get ignored), and can
> + * optionally also be used to help you avoid code bit-rot due to #ifdery

"ifdeffery"

> + * collateral.

... and I don't understand what "ifdeffery collateral" means.

> + */
> +
> +/**
> + * DOC: Linker table provenance and userspace testing
> + *
> + * The Linux implementation of linker tables is derivative of iPXE linker
> + * table's solution (iPXE commit 67a10ef000cb7 [0]).  To see how this code
> + * evolved or to extend and test and use this code in userspace refer to the

"... to extend, test and use... "

> + * userspace linker-table tree [1].  This repository can be used for ease of
> + * testing of extensions and sampling of changes prior to inclusion into Linux,
> + * it is intended to be kept up to date to match Linux's solution. Contrary to

Keeping different pieces of code in sync is always a PITA.

Can we automatically extract the kernel linker tables into a standalone
userspace pile of C code for experimentation? I.e., something like

make linker_tables_app

or so...

> + * iPXE's solution, which strives to force compilation of everything using

s/,//

> + * linker tables, Linux's solution allows for developers to be selective over
> + * where one wishes to force compilation, this then is just an optional feature
> + * for the Linux linker table solution.
> + *
> + * [0] git://git.ipxe.org/ipxe.git
> + *
> + * [1] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linker-tables.git/
> + */
> +
> +/**
> + * DOC: The code bit-rot problem
> + *
> + * Overuse of C #ifdefs can be problematic for certain types of code.  Linux
> + * provides a rich array of features, but all these features take up valuable
> + * space in a kernel image. The traditional solution to this problem has been
> + * for each feature to have its own Kconfig entry and for the respective code
> + * to be wrapped around #ifdefs, allowing the feature to be compiled in only
> + * if desired.

"... if enabled in Kconfig."

> + *
> + * The problem with this is that over time it becomes very difficult and time
> + * consuming to compile, let alone test, all possible versions of Linux. Code

					    "all possible Kconfig configurations."

> + * that is not typically used tends to suffer from bit-rot over time. It can
> + * become difficult to predict which combinations of compile-time options will
> + * result in code that can compile and link correctly.
> + */
> +
> +/**
> + * DOC: Avoiding the code bit-rot problem when desirable
> + *
> + * To solve the code bit-rot problem linker tables can be used on Linux, it

"One way to solve this ..."					 "... on Linux. It enables..."

> + * enables you to always force compiling of select features that one wishes to
> + * avoid bit-rot while still enabling you to disable linking feature code into
> + * the final kernel image if the features have been disabled via Kconfig.

So this sounds to me like the main reason for linker tables is solving
the bitrot problem. And I don't think that is the main reason for them,
is it?

Because we can address the bitrot issue by simply building randconfigs,
without even touching the kernel. So why do we need those linker tables?

> + * Linux's linker tables allows for developers to be selective over where one
> + * wishes to take advantage of the optional feature of forcing compilation and
> + * only linking in enabled features.
> + *
> + * To use linker tables and to optionally take advantage of avoiding code
> + * bit-rot, feature code should be implemented in separate C files, and should
> + * be designed to always be compiled -- they should not be guarded with a C
> + * code #ifdef CONFIG_FOO statements, consideration must also be taken for
> + * sub-features which depend on the main CONFIG_FOO option, as they will be
> + * disabled if they depend on CONFIG_FOO and therefore not compiled. To force
> + * compilation and only link when features are needed a new optional target
> + * table-y can be used on Makefiles, documented below.

Ok, this is more like it. Linker tables actually diminish the Kconfig
complexity. I'd lead with that.

> + *
> + * Currently only built-in features are supported, modular support is not
> + * yet supported,

"... modular support ... supported ... " Avoid tautology pls.

> however you can make use of sub-features for modules
> + * if they are independent and can simply be linked into modules.
> + */
> +
> +/**
> + * DOC: Using target table-y and table-n
> + *
> + * Let's assume we want to always force compilation of feature FOO in the
> + * kernel but avoid linking it. When you enable the FOO feature via Kconfig
> + * you'd end up with:
> + *
> + *	#define CONFIG_FOO 1
> + *
> + * You typically would then just use this on your Makefile to selectively

s/on/in/

> + * compile and link the feature:
> + *
> + *	obj-$(CONFIG_FOO) += foo.o
> + *
> + * You could instead optionally use the new linker table object:
> + *
> + *	table-$(CONFIG_FOO) += foo.o
> + *
> + * Alternatively, this would be the equivalent of listing:
> + *
> + *	extra += foo.o
> + *	obj-$(CONFIG_FOO) += foo.o
> + *
> + * Both are mechanisms which can be used to take advantage of forcing
> + * compilation with linker tables, however making use of table-$(CONFIG_FOO)
> + * is encouraged as it helps with annotating linker tables clearly where
> + * compilation is forced.
> + */
> +
> +/**
> + * DOC: Opting out of forcing compilation
> + *
> + * If you want to opt-out of forcing compilation you would use the typical
> + * obj-$(CONFIG_FOO) += foo.o and foo.o will only be compiled and linked
> + * in when enabled. Using both table-$(CONFIG_FOO) and obj-($CONFIG_FOO)

"... when CONFIG_FOO is enabled."

> + * will result with the feature on your binary only if you've enabled
> + * CONFIG_FOO, however using table-$(CONFIG_FOO) will always force compilation,
> + * this is why avoiding code bit-rot is an optional fature for Linux linker

"fature" - please run it through spellchecker.

Btw, I'm afraid this "table-$(CONFIG" thing might be misused by people
wanting their stuff to be compile-tested and we'd end up practically
building an allyesconfig each time.

So how can I disable those table-* things from even getting built? Avoid
using table-y?

But then everything declared table-y will be built unconditionally. I don't
think I like that. :-\

> + * tables.
> + */
> +
> +/**
> + * DOC: How linker tables simplify inits
> + *
> + * Traditionally, we would implement features in C code as follows:

Ok, so *this* is your main reason for linker tables - not fixing the
bit-rot problem. The text on the bit-rot problem should come second and
be the byproduct of linker tables.

Also, this section here should be the opening section in the document
explaining linker tables. I'd like to read about what it is first, then
read what else they're good for.

> + *
> + *	foo_init();
> + *
> + * You'd then have a foo.h which would have:
> + *
> + *	#ifdef CONFIG_FOO
> + *	#else
> + *	static inline void foo(void) { }
> + *	#endif
> + *
> + * With linker tables this is no longer necessary as your init routines would
> + * be implicit, you'd instead call:
> + *
> + *	call_init_fns();
> + *
> + * call_init_fns() would call all functions present in your init table and if
> + * and only if foo.o gets linked in, then its initialisation function will be
> + * called, whether you use obj-$(CONFIG_FOO) or table-$(CONFIG_FOO).
> + *
> + * The linker script takes care of assembling the tables for us. All of our
> + * table sections have names of the format SECTION_NAME*.tbl.NAME.N. Here

The fact that you actually say "tbl" here shows again SECTION_TYPE_TABLES is
redundant.

> + * SECTION_NAME is one of the standard sections in include/linux/sections.h,
> + * and NAME designates the specific use case for the linker table, the table.

								s/, the table//

<--- new paragraph starts here

> + * N is a digit decimal number used to impose an "order level" upon the tables

	digit *and* decimal number? :-)

> + * if required. NN= (empty string) is reserved for the symbol indicating "table

NN= or N= ?

> + * start", and N=~ is reserved for the symbol indicating "table end". In order
> + * for the call_init_fns() to work behind the scenes the custom linker script
> + * would need to define the beginning of the table, the end of the table, and
> + * in between it should use SORT() to give order-level effect. Now, typically

So basically N makes the section names sortable...

> + * such type of requirements would require custom linker script modifications

Duude, you're killing me: "such type of requirements would require"

> + * but Linux's linker tables builds on top of already existing standard Linux

				build

> + * ELF sections, each with different purposes. This lets you build and add
> + * new tables without needing custom linker script modifications. This is
> + * also done to support all architectures. All that is needed then is to
> + * ensure a respective common linker table entry is added to the shared
> + * include/asm-generic/vmlinux.lds.h.

<-- new paragraph starts here:

> There should be a respective:
> + *
> + *	*(SORT(SECTION_TBL_ALL(SECTION_NAME)))
> + *
> + * entry for each type of supported section there. If your SECTION_NAME
> + * is not yet supported, consider adding support for it.
> + *
> + * The order-level is really only a helper, if only one order level is

order-level??

What that?

> + * used, the next contributing factor to order is the order of the code
> + * in the C file, and the order of the objects in the Makefile. Using
> + * an order level then should not really be needed in most cases, its
> + * use however enables to compartamentalize code into tables where ordering
> + * through C file or through the Makefile would otherwise be very difficult
> + * or if one wanted to enable very specific initialization semantics.
> + *
> + * As an example, suppose that we want to create a "frobnicator"
> + * feature framework, and allow for several independent modules to
> + * provide frobnicating services. Then we would create a frob.h
> + * header file containing e.g.
> + *
> + *	struct frobnicator {
> + *		const char *name;
> + *		void (*frob) (void);
> + *	};
> + *
> + *	DECLARE_LINKTABLE(struct frobnicator, frobnicator_fns);
> + *
> + * Any module providing frobnicating services would look something
> + * like
> + *
> + *	#include "frob.h"
> + *	static void my_frob(void) {
> + *		... Do my frobnicating
> + *	}
> + *	LINKTABLE_INIT_DATA(frobnicator_fns, all) my_frobnicator = {
> + *		.name = "my_frob",
> + *		.frob = my_frob,
> + *	};
> + *
> + * The central frobnicator code (frob.c) would use the frobnicating
> + * modules as follows
> + *
> + *	#include "frob.h"
> + *
> + *	void frob_all(void) {
> + *		struct frob *frob;
> + *
> + *		LINKTABLE_FOR_EACH(frob, frobnicator_fns) {
> + *			pr_info("Calling frobnicator \"%s\"\n", frob->name);
> + *			frob->frob();
> + *		}
> + *	}
> + */
> +
> +/**
> + * DOC: Linker table helpers
> + *
> + * These are helpers for linker tables.
> + */

I'm assuming those are all needed and we're not adding them just for
completeness...

Otherwise, they'll bit-rot. :-))))

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-07-29 10:06     ` Borislav Petkov
  0 siblings, 0 replies; 176+ messages in thread
From: Borislav Petkov @ 2016-07-29 10:06 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, linux, mhiramat, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-

On Fri, Jul 22, 2016 at 02:24:41PM -0700, Luis R. Rodriguez wrote:
> 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
> originally based on Michael Brown's iPXE's linker table solution but
> has been significantly modified to fit Linux's use in its integration.

...

> diff --git a/include/asm-generic/tables.h b/include/asm-generic/tables.h
> new file mode 100644
> index 000000000000..5cf655590a19
> --- /dev/null
> +++ b/include/asm-generic/tables.h
> @@ -0,0 +1,70 @@
> +#ifndef _ASM_GENERIC_TABLES_H_
> +#define _ASM_GENERIC_TABLES_H_
> +/*
> + * Linux linker tables
> + *
> + * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
> + *
> + * 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/.
> + */
> +
> +#ifdef __KERNEL__
> +# include <asm/sections.h>
> +#endif /* __KERNEL__ */
> +
> +#define SECTION_TYPE_TABLES	tbl

What is that for? Section type? Do we have more types or is it useless
and can go?

> +
> +#define SECTION_TBL(section, name, level)				\
> +	SECTION_TYPE(section, SECTION_TYPE_TABLES, name, level)
> +
> +#define SECTION_TBL_ALL(section)					\
> +	SECTION_TYPE_ALL(section,SECTION_TYPE_TABLES)
> +
> +#ifndef section_tbl
> +# define section_tbl(section, name, level, flags)			\
> +	 section_type(section, SECTION_TYPE_TABLES, name,		\
> +		     level, flags)

That section_type macro is actually saying the following code should
be in it. Can we make its name have a verb, i.e., something like
"set_section" to make it more clear?

Also, that type SECTION_TYPE_TABLES looks redundant to me but it
might start making more sense after I've gone through the rest of the
series...

> +#endif
> +
> +#ifndef section_tbl_any
> +# define section_tbl_any(section, name, flags)				\
> +	 section_type(section, SECTION_TYPE_TABLES, name,		\
> +		     SECTION_ORDER_ANY, flags)
> +#endif
> +
> +#ifndef section_tbl_asmtype
> +# define section_tbl_asmtype(section, name, level, flags, asmtype)	\

And here's the confusion: there's "asmtype" but there's also
SECTION_TYPE_TABLES.

That asmtype is the *actual* section type in gas speak, i.e., @progbits,
@note, etc.

Now *that* should be your type. The SECTION_TYPE_TABLES should be called
something else or completely gone.

> +	 section_type_asmtype(section, SECTION_TYPE_TABLES, name,	\
> +			     level, flags, asmtype)
> +#endif
> +
> +#ifndef push_section_tbl
> +# define push_section_tbl(section, name, level, flags)			\
> +	 push_section_type(section, SECTION_TYPE_TABLES, name,		\
> +			  level, flags)
> +#endif
> +
> +#ifndef push_section_tbl_any
> +# define push_section_tbl_any(section, name, flags)			\
> +	 push_section_type(section, SECTION_TYPE_TABLES, name,		\
> +			  SECTION_ORDER_ANY, flags)
> +#endif
> +
> +#if defined(__ASSEMBLER__) || defined(__ASSEMBLY__)
> +
> +# ifndef DECLARE_SECTION_TBL
> +#  define DECLARE_SECTION_TBL(section, name)				\
> +  push_section_tbl(section, name,,) ;					\
> +  .globl name ;								\
> +name: ;									\
> +  .popsection								\
> +									\
> +  push_section_tbl(section, name, ~,) ;					\
> +  .popsection
> +# endif

#endif /* DECLARE_SECTION_TBL */

Btw, what does that macro do? I don't see it used anywhere.

> +
> +#endif /* defined(__ASSEMBLER__) || defined(__ASSEMBLY__) */
> +
> +#endif /* _ASM_GENERIC_TABLES_H_ */


...


> diff --git a/include/linux/tables.h b/include/linux/tables.h
> new file mode 100644
> index 000000000000..89d46f4c5739
> --- /dev/null
> +++ b/include/linux/tables.h
> @@ -0,0 +1,597 @@
> +#ifndef _LINUX_LINKER_TABLES_H
> +#define _LINUX_LINKER_TABLES_H
> +/*
> + * Linux linker tables
> + *
> + * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
> + *
> + * 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 <linux/sections.h>
> +#ifdef __KERNEL__
> +# include <asm/tables.h>
> +#endif /* __KERNEL__ */
> +
> +#ifndef __ASSEMBLY__
> +
> +/**
> + * DOC: Introduction
> + *
> + * A linker table is a data structure that is stitched together from items
> + * in multiple object files. Linux has historically implicitly used linker

s/historically//

"for ages" already says "historically" :-)

> + * tables for ages, however they were all built in an adhoc manner which
> + * requires linker script modifications, per architecture. This linker table

s/,//

> + * solution provides a general linker table facility so that a new linker table
> + * can be implemented by changing C code only.
> + *
> + * Linker tables help you simplify init sequences by using ELF sections, linker
> + * build time selective sorting (disabled options get ignored), and can
> + * optionally also be used to help you avoid code bit-rot due to #ifdery

"ifdeffery"

> + * collateral.

... and I don't understand what "ifdeffery collateral" means.

> + */
> +
> +/**
> + * DOC: Linker table provenance and userspace testing
> + *
> + * The Linux implementation of linker tables is derivative of iPXE linker
> + * table's solution (iPXE commit 67a10ef000cb7 [0]).  To see how this code
> + * evolved or to extend and test and use this code in userspace refer to the

"... to extend, test and use... "

> + * userspace linker-table tree [1].  This repository can be used for ease of
> + * testing of extensions and sampling of changes prior to inclusion into Linux,
> + * it is intended to be kept up to date to match Linux's solution. Contrary to

Keeping different pieces of code in sync is always a PITA.

Can we automatically extract the kernel linker tables into a standalone
userspace pile of C code for experimentation? I.e., something like

make linker_tables_app

or so...

> + * iPXE's solution, which strives to force compilation of everything using

s/,//

> + * linker tables, Linux's solution allows for developers to be selective over
> + * where one wishes to force compilation, this then is just an optional feature
> + * for the Linux linker table solution.
> + *
> + * [0] git://git.ipxe.org/ipxe.git
> + *
> + * [1] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linker-tables.git/
> + */
> +
> +/**
> + * DOC: The code bit-rot problem
> + *
> + * Overuse of C #ifdefs can be problematic for certain types of code.  Linux
> + * provides a rich array of features, but all these features take up valuable
> + * space in a kernel image. The traditional solution to this problem has been
> + * for each feature to have its own Kconfig entry and for the respective code
> + * to be wrapped around #ifdefs, allowing the feature to be compiled in only
> + * if desired.

"... if enabled in Kconfig."

> + *
> + * The problem with this is that over time it becomes very difficult and time
> + * consuming to compile, let alone test, all possible versions of Linux. Code

					    "all possible Kconfig configurations."

> + * that is not typically used tends to suffer from bit-rot over time. It can
> + * become difficult to predict which combinations of compile-time options will
> + * result in code that can compile and link correctly.
> + */
> +
> +/**
> + * DOC: Avoiding the code bit-rot problem when desirable
> + *
> + * To solve the code bit-rot problem linker tables can be used on Linux, it

"One way to solve this ..."					 "... on Linux. It enables..."

> + * enables you to always force compiling of select features that one wishes to
> + * avoid bit-rot while still enabling you to disable linking feature code into
> + * the final kernel image if the features have been disabled via Kconfig.

So this sounds to me like the main reason for linker tables is solving
the bitrot problem. And I don't think that is the main reason for them,
is it?

Because we can address the bitrot issue by simply building randconfigs,
without even touching the kernel. So why do we need those linker tables?

> + * Linux's linker tables allows for developers to be selective over where one
> + * wishes to take advantage of the optional feature of forcing compilation and
> + * only linking in enabled features.
> + *
> + * To use linker tables and to optionally take advantage of avoiding code
> + * bit-rot, feature code should be implemented in separate C files, and should
> + * be designed to always be compiled -- they should not be guarded with a C
> + * code #ifdef CONFIG_FOO statements, consideration must also be taken for
> + * sub-features which depend on the main CONFIG_FOO option, as they will be
> + * disabled if they depend on CONFIG_FOO and therefore not compiled. To force
> + * compilation and only link when features are needed a new optional target
> + * table-y can be used on Makefiles, documented below.

Ok, this is more like it. Linker tables actually diminish the Kconfig
complexity. I'd lead with that.

> + *
> + * Currently only built-in features are supported, modular support is not
> + * yet supported,

"... modular support ... supported ... " Avoid tautology pls.

> however you can make use of sub-features for modules
> + * if they are independent and can simply be linked into modules.
> + */
> +
> +/**
> + * DOC: Using target table-y and table-n
> + *
> + * Let's assume we want to always force compilation of feature FOO in the
> + * kernel but avoid linking it. When you enable the FOO feature via Kconfig
> + * you'd end up with:
> + *
> + *	#define CONFIG_FOO 1
> + *
> + * You typically would then just use this on your Makefile to selectively

s/on/in/

> + * compile and link the feature:
> + *
> + *	obj-$(CONFIG_FOO) += foo.o
> + *
> + * You could instead optionally use the new linker table object:
> + *
> + *	table-$(CONFIG_FOO) += foo.o
> + *
> + * Alternatively, this would be the equivalent of listing:
> + *
> + *	extra += foo.o
> + *	obj-$(CONFIG_FOO) += foo.o
> + *
> + * Both are mechanisms which can be used to take advantage of forcing
> + * compilation with linker tables, however making use of table-$(CONFIG_FOO)
> + * is encouraged as it helps with annotating linker tables clearly where
> + * compilation is forced.
> + */
> +
> +/**
> + * DOC: Opting out of forcing compilation
> + *
> + * If you want to opt-out of forcing compilation you would use the typical
> + * obj-$(CONFIG_FOO) += foo.o and foo.o will only be compiled and linked
> + * in when enabled. Using both table-$(CONFIG_FOO) and obj-($CONFIG_FOO)

"... when CONFIG_FOO is enabled."

> + * will result with the feature on your binary only if you've enabled
> + * CONFIG_FOO, however using table-$(CONFIG_FOO) will always force compilation,
> + * this is why avoiding code bit-rot is an optional fature for Linux linker

"fature" - please run it through spellchecker.

Btw, I'm afraid this "table-$(CONFIG" thing might be misused by people
wanting their stuff to be compile-tested and we'd end up practically
building an allyesconfig each time.

So how can I disable those table-* things from even getting built? Avoid
using table-y?

But then everything declared table-y will be built unconditionally. I don't
think I like that. :-\

> + * tables.
> + */
> +
> +/**
> + * DOC: How linker tables simplify inits
> + *
> + * Traditionally, we would implement features in C code as follows:

Ok, so *this* is your main reason for linker tables - not fixing the
bit-rot problem. The text on the bit-rot problem should come second and
be the byproduct of linker tables.

Also, this section here should be the opening section in the document
explaining linker tables. I'd like to read about what it is first, then
read what else they're good for.

> + *
> + *	foo_init();
> + *
> + * You'd then have a foo.h which would have:
> + *
> + *	#ifdef CONFIG_FOO
> + *	#else
> + *	static inline void foo(void) { }
> + *	#endif
> + *
> + * With linker tables this is no longer necessary as your init routines would
> + * be implicit, you'd instead call:
> + *
> + *	call_init_fns();
> + *
> + * call_init_fns() would call all functions present in your init table and if
> + * and only if foo.o gets linked in, then its initialisation function will be
> + * called, whether you use obj-$(CONFIG_FOO) or table-$(CONFIG_FOO).
> + *
> + * The linker script takes care of assembling the tables for us. All of our
> + * table sections have names of the format SECTION_NAME*.tbl.NAME.N. Here

The fact that you actually say "tbl" here shows again SECTION_TYPE_TABLES is
redundant.

> + * SECTION_NAME is one of the standard sections in include/linux/sections.h,
> + * and NAME designates the specific use case for the linker table, the table.

								s/, the table//

<--- new paragraph starts here

> + * N is a digit decimal number used to impose an "order level" upon the tables

	digit *and* decimal number? :-)

> + * if required. NN= (empty string) is reserved for the symbol indicating "table

NN= or N= ?

> + * start", and N=~ is reserved for the symbol indicating "table end". In order
> + * for the call_init_fns() to work behind the scenes the custom linker script
> + * would need to define the beginning of the table, the end of the table, and
> + * in between it should use SORT() to give order-level effect. Now, typically

So basically N makes the section names sortable...

> + * such type of requirements would require custom linker script modifications

Duude, you're killing me: "such type of requirements would require"

> + * but Linux's linker tables builds on top of already existing standard Linux

				build

> + * ELF sections, each with different purposes. This lets you build and add
> + * new tables without needing custom linker script modifications. This is
> + * also done to support all architectures. All that is needed then is to
> + * ensure a respective common linker table entry is added to the shared
> + * include/asm-generic/vmlinux.lds.h.

<-- new paragraph starts here:

> There should be a respective:
> + *
> + *	*(SORT(SECTION_TBL_ALL(SECTION_NAME)))
> + *
> + * entry for each type of supported section there. If your SECTION_NAME
> + * is not yet supported, consider adding support for it.
> + *
> + * The order-level is really only a helper, if only one order level is

order-level??

What that?

> + * used, the next contributing factor to order is the order of the code
> + * in the C file, and the order of the objects in the Makefile. Using
> + * an order level then should not really be needed in most cases, its
> + * use however enables to compartamentalize code into tables where ordering
> + * through C file or through the Makefile would otherwise be very difficult
> + * or if one wanted to enable very specific initialization semantics.
> + *
> + * As an example, suppose that we want to create a "frobnicator"
> + * feature framework, and allow for several independent modules to
> + * provide frobnicating services. Then we would create a frob.h
> + * header file containing e.g.
> + *
> + *	struct frobnicator {
> + *		const char *name;
> + *		void (*frob) (void);
> + *	};
> + *
> + *	DECLARE_LINKTABLE(struct frobnicator, frobnicator_fns);
> + *
> + * Any module providing frobnicating services would look something
> + * like
> + *
> + *	#include "frob.h"
> + *	static void my_frob(void) {
> + *		... Do my frobnicating
> + *	}
> + *	LINKTABLE_INIT_DATA(frobnicator_fns, all) my_frobnicator = {
> + *		.name = "my_frob",
> + *		.frob = my_frob,
> + *	};
> + *
> + * The central frobnicator code (frob.c) would use the frobnicating
> + * modules as follows
> + *
> + *	#include "frob.h"
> + *
> + *	void frob_all(void) {
> + *		struct frob *frob;
> + *
> + *		LINKTABLE_FOR_EACH(frob, frobnicator_fns) {
> + *			pr_info("Calling frobnicator \"%s\"\n", frob->name);
> + *			frob->frob();
> + *		}
> + *	}
> + */
> +
> +/**
> + * DOC: Linker table helpers
> + *
> + * These are helpers for linker tables.
> + */

I'm assuming those are all needed and we're not adding them just for
completeness...

Otherwise, they'll bit-rot. :-))))

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-07-29 10:06     ` Borislav Petkov
  0 siblings, 0 replies; 176+ messages in thread
From: Borislav Petkov @ 2016-07-29 10:06 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, linux, mhiramat, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe

On Fri, Jul 22, 2016 at 02:24:41PM -0700, Luis R. Rodriguez wrote:
> 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
> originally based on Michael Brown's iPXE's linker table solution but
> has been significantly modified to fit Linux's use in its integration.

...

> diff --git a/include/asm-generic/tables.h b/include/asm-generic/tables.h
> new file mode 100644
> index 000000000000..5cf655590a19
> --- /dev/null
> +++ b/include/asm-generic/tables.h
> @@ -0,0 +1,70 @@
> +#ifndef _ASM_GENERIC_TABLES_H_
> +#define _ASM_GENERIC_TABLES_H_
> +/*
> + * Linux linker tables
> + *
> + * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
> + *
> + * 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/.
> + */
> +
> +#ifdef __KERNEL__
> +# include <asm/sections.h>
> +#endif /* __KERNEL__ */
> +
> +#define SECTION_TYPE_TABLES	tbl

What is that for? Section type? Do we have more types or is it useless
and can go?

> +
> +#define SECTION_TBL(section, name, level)				\
> +	SECTION_TYPE(section, SECTION_TYPE_TABLES, name, level)
> +
> +#define SECTION_TBL_ALL(section)					\
> +	SECTION_TYPE_ALL(section,SECTION_TYPE_TABLES)
> +
> +#ifndef section_tbl
> +# define section_tbl(section, name, level, flags)			\
> +	 section_type(section, SECTION_TYPE_TABLES, name,		\
> +		     level, flags)

That section_type macro is actually saying the following code should
be in it. Can we make its name have a verb, i.e., something like
"set_section" to make it more clear?

Also, that type SECTION_TYPE_TABLES looks redundant to me but it
might start making more sense after I've gone through the rest of the
series...

> +#endif
> +
> +#ifndef section_tbl_any
> +# define section_tbl_any(section, name, flags)				\
> +	 section_type(section, SECTION_TYPE_TABLES, name,		\
> +		     SECTION_ORDER_ANY, flags)
> +#endif
> +
> +#ifndef section_tbl_asmtype
> +# define section_tbl_asmtype(section, name, level, flags, asmtype)	\

And here's the confusion: there's "asmtype" but there's also
SECTION_TYPE_TABLES.

That asmtype is the *actual* section type in gas speak, i.e., @progbits,
@note, etc.

Now *that* should be your type. The SECTION_TYPE_TABLES should be called
something else or completely gone.

> +	 section_type_asmtype(section, SECTION_TYPE_TABLES, name,	\
> +			     level, flags, asmtype)
> +#endif
> +
> +#ifndef push_section_tbl
> +# define push_section_tbl(section, name, level, flags)			\
> +	 push_section_type(section, SECTION_TYPE_TABLES, name,		\
> +			  level, flags)
> +#endif
> +
> +#ifndef push_section_tbl_any
> +# define push_section_tbl_any(section, name, flags)			\
> +	 push_section_type(section, SECTION_TYPE_TABLES, name,		\
> +			  SECTION_ORDER_ANY, flags)
> +#endif
> +
> +#if defined(__ASSEMBLER__) || defined(__ASSEMBLY__)
> +
> +# ifndef DECLARE_SECTION_TBL
> +#  define DECLARE_SECTION_TBL(section, name)				\
> +  push_section_tbl(section, name,,) ;					\
> +  .globl name ;								\
> +name: ;									\
> +  .popsection								\
> +									\
> +  push_section_tbl(section, name, ~,) ;					\
> +  .popsection
> +# endif

#endif /* DECLARE_SECTION_TBL */

Btw, what does that macro do? I don't see it used anywhere.

> +
> +#endif /* defined(__ASSEMBLER__) || defined(__ASSEMBLY__) */
> +
> +#endif /* _ASM_GENERIC_TABLES_H_ */


...


> diff --git a/include/linux/tables.h b/include/linux/tables.h
> new file mode 100644
> index 000000000000..89d46f4c5739
> --- /dev/null
> +++ b/include/linux/tables.h
> @@ -0,0 +1,597 @@
> +#ifndef _LINUX_LINKER_TABLES_H
> +#define _LINUX_LINKER_TABLES_H
> +/*
> + * Linux linker tables
> + *
> + * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
> + *
> + * 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 <linux/sections.h>
> +#ifdef __KERNEL__
> +# include <asm/tables.h>
> +#endif /* __KERNEL__ */
> +
> +#ifndef __ASSEMBLY__
> +
> +/**
> + * DOC: Introduction
> + *
> + * A linker table is a data structure that is stitched together from items
> + * in multiple object files. Linux has historically implicitly used linker

s/historically//

"for ages" already says "historically" :-)

> + * tables for ages, however they were all built in an adhoc manner which
> + * requires linker script modifications, per architecture. This linker table

s/,//

> + * solution provides a general linker table facility so that a new linker table
> + * can be implemented by changing C code only.
> + *
> + * Linker tables help you simplify init sequences by using ELF sections, linker
> + * build time selective sorting (disabled options get ignored), and can
> + * optionally also be used to help you avoid code bit-rot due to #ifdery

"ifdeffery"

> + * collateral.

... and I don't understand what "ifdeffery collateral" means.

> + */
> +
> +/**
> + * DOC: Linker table provenance and userspace testing
> + *
> + * The Linux implementation of linker tables is derivative of iPXE linker
> + * table's solution (iPXE commit 67a10ef000cb7 [0]).  To see how this code
> + * evolved or to extend and test and use this code in userspace refer to the

"... to extend, test and use... "

> + * userspace linker-table tree [1].  This repository can be used for ease of
> + * testing of extensions and sampling of changes prior to inclusion into Linux,
> + * it is intended to be kept up to date to match Linux's solution. Contrary to

Keeping different pieces of code in sync is always a PITA.

Can we automatically extract the kernel linker tables into a standalone
userspace pile of C code for experimentation? I.e., something like

make linker_tables_app

or so...

> + * iPXE's solution, which strives to force compilation of everything using

s/,//

> + * linker tables, Linux's solution allows for developers to be selective over
> + * where one wishes to force compilation, this then is just an optional feature
> + * for the Linux linker table solution.
> + *
> + * [0] git://git.ipxe.org/ipxe.git
> + *
> + * [1] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linker-tables.git/
> + */
> +
> +/**
> + * DOC: The code bit-rot problem
> + *
> + * Overuse of C #ifdefs can be problematic for certain types of code.  Linux
> + * provides a rich array of features, but all these features take up valuable
> + * space in a kernel image. The traditional solution to this problem has been
> + * for each feature to have its own Kconfig entry and for the respective code
> + * to be wrapped around #ifdefs, allowing the feature to be compiled in only
> + * if desired.

"... if enabled in Kconfig."

> + *
> + * The problem with this is that over time it becomes very difficult and time
> + * consuming to compile, let alone test, all possible versions of Linux. Code

					    "all possible Kconfig configurations."

> + * that is not typically used tends to suffer from bit-rot over time. It can
> + * become difficult to predict which combinations of compile-time options will
> + * result in code that can compile and link correctly.
> + */
> +
> +/**
> + * DOC: Avoiding the code bit-rot problem when desirable
> + *
> + * To solve the code bit-rot problem linker tables can be used on Linux, it

"One way to solve this ..."					 "... on Linux. It enables..."

> + * enables you to always force compiling of select features that one wishes to
> + * avoid bit-rot while still enabling you to disable linking feature code into
> + * the final kernel image if the features have been disabled via Kconfig.

So this sounds to me like the main reason for linker tables is solving
the bitrot problem. And I don't think that is the main reason for them,
is it?

Because we can address the bitrot issue by simply building randconfigs,
without even touching the kernel. So why do we need those linker tables?

> + * Linux's linker tables allows for developers to be selective over where one
> + * wishes to take advantage of the optional feature of forcing compilation and
> + * only linking in enabled features.
> + *
> + * To use linker tables and to optionally take advantage of avoiding code
> + * bit-rot, feature code should be implemented in separate C files, and should
> + * be designed to always be compiled -- they should not be guarded with a C
> + * code #ifdef CONFIG_FOO statements, consideration must also be taken for
> + * sub-features which depend on the main CONFIG_FOO option, as they will be
> + * disabled if they depend on CONFIG_FOO and therefore not compiled. To force
> + * compilation and only link when features are needed a new optional target
> + * table-y can be used on Makefiles, documented below.

Ok, this is more like it. Linker tables actually diminish the Kconfig
complexity. I'd lead with that.

> + *
> + * Currently only built-in features are supported, modular support is not
> + * yet supported,

"... modular support ... supported ... " Avoid tautology pls.

> however you can make use of sub-features for modules
> + * if they are independent and can simply be linked into modules.
> + */
> +
> +/**
> + * DOC: Using target table-y and table-n
> + *
> + * Let's assume we want to always force compilation of feature FOO in the
> + * kernel but avoid linking it. When you enable the FOO feature via Kconfig
> + * you'd end up with:
> + *
> + *	#define CONFIG_FOO 1
> + *
> + * You typically would then just use this on your Makefile to selectively

s/on/in/

> + * compile and link the feature:
> + *
> + *	obj-$(CONFIG_FOO) += foo.o
> + *
> + * You could instead optionally use the new linker table object:
> + *
> + *	table-$(CONFIG_FOO) += foo.o
> + *
> + * Alternatively, this would be the equivalent of listing:
> + *
> + *	extra += foo.o
> + *	obj-$(CONFIG_FOO) += foo.o
> + *
> + * Both are mechanisms which can be used to take advantage of forcing
> + * compilation with linker tables, however making use of table-$(CONFIG_FOO)
> + * is encouraged as it helps with annotating linker tables clearly where
> + * compilation is forced.
> + */
> +
> +/**
> + * DOC: Opting out of forcing compilation
> + *
> + * If you want to opt-out of forcing compilation you would use the typical
> + * obj-$(CONFIG_FOO) += foo.o and foo.o will only be compiled and linked
> + * in when enabled. Using both table-$(CONFIG_FOO) and obj-($CONFIG_FOO)

"... when CONFIG_FOO is enabled."

> + * will result with the feature on your binary only if you've enabled
> + * CONFIG_FOO, however using table-$(CONFIG_FOO) will always force compilation,
> + * this is why avoiding code bit-rot is an optional fature for Linux linker

"fature" - please run it through spellchecker.

Btw, I'm afraid this "table-$(CONFIG" thing might be misused by people
wanting their stuff to be compile-tested and we'd end up practically
building an allyesconfig each time.

So how can I disable those table-* things from even getting built? Avoid
using table-y?

But then everything declared table-y will be built unconditionally. I don't
think I like that. :-\

> + * tables.
> + */
> +
> +/**
> + * DOC: How linker tables simplify inits
> + *
> + * Traditionally, we would implement features in C code as follows:

Ok, so *this* is your main reason for linker tables - not fixing the
bit-rot problem. The text on the bit-rot problem should come second and
be the byproduct of linker tables.

Also, this section here should be the opening section in the document
explaining linker tables. I'd like to read about what it is first, then
read what else they're good for.

> + *
> + *	foo_init();
> + *
> + * You'd then have a foo.h which would have:
> + *
> + *	#ifdef CONFIG_FOO
> + *	#else
> + *	static inline void foo(void) { }
> + *	#endif
> + *
> + * With linker tables this is no longer necessary as your init routines would
> + * be implicit, you'd instead call:
> + *
> + *	call_init_fns();
> + *
> + * call_init_fns() would call all functions present in your init table and if
> + * and only if foo.o gets linked in, then its initialisation function will be
> + * called, whether you use obj-$(CONFIG_FOO) or table-$(CONFIG_FOO).
> + *
> + * The linker script takes care of assembling the tables for us. All of our
> + * table sections have names of the format SECTION_NAME*.tbl.NAME.N. Here

The fact that you actually say "tbl" here shows again SECTION_TYPE_TABLES is
redundant.

> + * SECTION_NAME is one of the standard sections in include/linux/sections.h,
> + * and NAME designates the specific use case for the linker table, the table.

								s/, the table//

<--- new paragraph starts here

> + * N is a digit decimal number used to impose an "order level" upon the tables

	digit *and* decimal number? :-)

> + * if required. NN= (empty string) is reserved for the symbol indicating "table

NN= or N= ?

> + * start", and N=~ is reserved for the symbol indicating "table end". In order
> + * for the call_init_fns() to work behind the scenes the custom linker script
> + * would need to define the beginning of the table, the end of the table, and
> + * in between it should use SORT() to give order-level effect. Now, typically

So basically N makes the section names sortable...

> + * such type of requirements would require custom linker script modifications

Duude, you're killing me: "such type of requirements would require"

> + * but Linux's linker tables builds on top of already existing standard Linux

				build

> + * ELF sections, each with different purposes. This lets you build and add
> + * new tables without needing custom linker script modifications. This is
> + * also done to support all architectures. All that is needed then is to
> + * ensure a respective common linker table entry is added to the shared
> + * include/asm-generic/vmlinux.lds.h.

<-- new paragraph starts here:

> There should be a respective:
> + *
> + *	*(SORT(SECTION_TBL_ALL(SECTION_NAME)))
> + *
> + * entry for each type of supported section there. If your SECTION_NAME
> + * is not yet supported, consider adding support for it.
> + *
> + * The order-level is really only a helper, if only one order level is

order-level??

What that?

> + * used, the next contributing factor to order is the order of the code
> + * in the C file, and the order of the objects in the Makefile. Using
> + * an order level then should not really be needed in most cases, its
> + * use however enables to compartamentalize code into tables where ordering
> + * through C file or through the Makefile would otherwise be very difficult
> + * or if one wanted to enable very specific initialization semantics.
> + *
> + * As an example, suppose that we want to create a "frobnicator"
> + * feature framework, and allow for several independent modules to
> + * provide frobnicating services. Then we would create a frob.h
> + * header file containing e.g.
> + *
> + *	struct frobnicator {
> + *		const char *name;
> + *		void (*frob) (void);
> + *	};
> + *
> + *	DECLARE_LINKTABLE(struct frobnicator, frobnicator_fns);
> + *
> + * Any module providing frobnicating services would look something
> + * like
> + *
> + *	#include "frob.h"
> + *	static void my_frob(void) {
> + *		... Do my frobnicating
> + *	}
> + *	LINKTABLE_INIT_DATA(frobnicator_fns, all) my_frobnicator = {
> + *		.name = "my_frob",
> + *		.frob = my_frob,
> + *	};
> + *
> + * The central frobnicator code (frob.c) would use the frobnicating
> + * modules as follows
> + *
> + *	#include "frob.h"
> + *
> + *	void frob_all(void) {
> + *		struct frob *frob;
> + *
> + *		LINKTABLE_FOR_EACH(frob, frobnicator_fns) {
> + *			pr_info("Calling frobnicator \"%s\"\n", frob->name);
> + *			frob->frob();
> + *		}
> + *	}
> + */
> +
> +/**
> + * DOC: Linker table helpers
> + *
> + * These are helpers for linker tables.
> + */

I'm assuming those are all needed and we're not adding them just for
completeness...

Otherwise, they'll bit-rot. :-))))

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 05/13] sections.h: add sections header to collect all section info
  2016-07-22 21:37     ` James Hogan
  (?)
@ 2016-07-29 17:28       ` Steven Rostedt
  -1 siblings, 0 replies; 176+ messages in thread
From: Steven Rostedt @ 2016-07-29 17:28 UTC (permalink / raw)
  To: James Hogan
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevche

On Fri, 22 Jul 2016 22:37:16 +0100
James Hogan <james.hogan@imgtec.com> wrote:


> > --- /dev/null
> > +++ b/arch/alpha/include/asm/sections.h
> > @@ -0,0 +1,6 @@
> > +#ifndef _ASM_ALPHA_SECTIONS_H
> > +#define _ASM_ALPHA_SECTIONS_H
> > +
> > +#include <asm-generic/sections.h>
> > +
> > +#endif /* _ASM_ALPHA_SECTIONS_H */  
> 
> Any particular reason not to use generic-y in the Kbuild files for
> sections.h, ranges.h, and tables.h?

One of my TODOs is to simplify that process. That is, to get rid of the
having to add it to all archs and get rid of the Kbuild file altogether.

-- Steve

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 05/13] sections.h: add sections header to collect all section info
@ 2016-07-29 17:28       ` Steven Rostedt
  0 siblings, 0 replies; 176+ messages in thread
From: Steven Rostedt @ 2016-07-29 17:28 UTC (permalink / raw)
  To: James Hogan
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevche

On Fri, 22 Jul 2016 22:37:16 +0100
James Hogan <james.hogan@imgtec.com> wrote:


> > --- /dev/null
> > +++ b/arch/alpha/include/asm/sections.h
> > @@ -0,0 +1,6 @@
> > +#ifndef _ASM_ALPHA_SECTIONS_H
> > +#define _ASM_ALPHA_SECTIONS_H
> > +
> > +#include <asm-generic/sections.h>
> > +
> > +#endif /* _ASM_ALPHA_SECTIONS_H */  
> 
> Any particular reason not to use generic-y in the Kbuild files for
> sections.h, ranges.h, and tables.h?

One of my TODOs is to simplify that process. That is, to get rid of the
having to add it to all archs and get rid of the Kbuild file altogether.

-- Steve

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 05/13] sections.h: add sections header to collect all section info
@ 2016-07-29 17:28       ` Steven Rostedt
  0 siblings, 0 replies; 176+ messages in thread
From: Steven Rostedt @ 2016-07-29 17:28 UTC (permalink / raw)
  To: James Hogan
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker, xen-devel, ak,
	pali.rohar, dvhart, platform-driver-x86, mmarek, linux, jkosina,
	korea.drzix, linux-kbuild, tony.luck, akpm, linux-ia64,
	linux-arm-kernel, linux-sh, sparclinux, catalin.marinas,
	will.deacon, jpoimboe

On Fri, 22 Jul 2016 22:37:16 +0100
James Hogan <james.hogan@imgtec.com> wrote:


> > --- /dev/null
> > +++ b/arch/alpha/include/asm/sections.h
> > @@ -0,0 +1,6 @@
> > +#ifndef _ASM_ALPHA_SECTIONS_H
> > +#define _ASM_ALPHA_SECTIONS_H
> > +
> > +#include <asm-generic/sections.h>
> > +
> > +#endif /* _ASM_ALPHA_SECTIONS_H */  
> 
> Any particular reason not to use generic-y in the Kbuild files for
> sections.h, ranges.h, and tables.h?

One of my TODOs is to simplify that process. That is, to get rid of the
having to add it to all archs and get rid of the Kbuild file altogether.

-- Steve

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-07-29 10:06     ` Borislav Petkov
  (?)
@ 2016-08-08 15:05       ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-08 15:05 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko

On Fri, Jul 29, 2016 at 12:06:30PM +0200, Borislav Petkov wrote:
> On Fri, Jul 22, 2016 at 02:24:41PM -0700, Luis R. Rodriguez wrote:
> > 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
> > originally based on Michael Brown's iPXE's linker table solution but
> > has been significantly modified to fit Linux's use in its integration.
> 
> ...
> 
> > diff --git a/include/asm-generic/tables.h b/include/asm-generic/tables.h
> > new file mode 100644
> > index 000000000000..5cf655590a19
> > --- /dev/null
> > +++ b/include/asm-generic/tables.h
> > @@ -0,0 +1,70 @@
> > +#ifndef _ASM_GENERIC_TABLES_H_
> > +#define _ASM_GENERIC_TABLES_H_
> > +/*
> > + * Linux linker tables
> > + *
> > + * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
> > + *
> > + * 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/.
> > + */
> > +
> > +#ifdef __KERNEL__
> > +# include <asm/sections.h>
> > +#endif /* __KERNEL__ */
> > +
> > +#define SECTION_TYPE_TABLES	tbl
> 
> What is that for? Section type? Do we have more types or is it useless
> and can go?

We have two types, tables and ranges. But I'll drop that.

> > +
> > +#define SECTION_TBL(section, name, level)				\
> > +	SECTION_TYPE(section, SECTION_TYPE_TABLES, name, level)
> > +
> > +#define SECTION_TBL_ALL(section)					\
> > +	SECTION_TYPE_ALL(section,SECTION_TYPE_TABLES)
> > +
> > +#ifndef section_tbl
> > +# define section_tbl(section, name, level, flags)			\
> > +	 section_type(section, SECTION_TYPE_TABLES, name,		\
> > +		     level, flags)
> 
> That section_type macro is actually saying the following code should
> be in it. Can we make its name have a verb, i.e., something like
> "set_section" to make it more clear?

Sure, thanks changed.

> Also, that type SECTION_TYPE_TABLES looks redundant to me but it
> might start making more sense after I've gone through the rest of the
> series...

I've dropped the type thing.

> > +#endif
> > +
> > +#ifndef section_tbl_any
> > +# define section_tbl_any(section, name, flags)				\
> > +	 section_type(section, SECTION_TYPE_TABLES, name,		\
> > +		     SECTION_ORDER_ANY, flags)
> > +#endif
> > +
> > +#ifndef section_tbl_asmtype
> > +# define section_tbl_asmtype(section, name, level, flags, asmtype)	\
> 
> And here's the confusion: there's "asmtype" but there's also
> SECTION_TYPE_TABLES.
> 
> That asmtype is the *actual* section type in gas speak, i.e., @progbits,
> @note, etc.
> 
> Now *that* should be your type. The SECTION_TYPE_TABLES should be called
> something else or completely gone.

Right, OK dropped and only kept type for this.

> > +	 section_type_asmtype(section, SECTION_TYPE_TABLES, name,	\
> > +			     level, flags, asmtype)
> > +#endif
> > +
> > +#ifndef push_section_tbl
> > +# define push_section_tbl(section, name, level, flags)			\
> > +	 push_section_type(section, SECTION_TYPE_TABLES, name,		\
> > +			  level, flags)
> > +#endif
> > +
> > +#ifndef push_section_tbl_any
> > +# define push_section_tbl_any(section, name, flags)			\
> > +	 push_section_type(section, SECTION_TYPE_TABLES, name,		\
> > +			  SECTION_ORDER_ANY, flags)
> > +#endif
> > +
> > +#if defined(__ASSEMBLER__) || defined(__ASSEMBLY__)
> > +
> > +# ifndef DECLARE_SECTION_TBL
> > +#  define DECLARE_SECTION_TBL(section, name)				\
> > +  push_section_tbl(section, name,,) ;					\
> > +  .globl name ;								\
> > +name: ;									\
> > +  .popsection								\
> > +									\
> > +  push_section_tbl(section, name, ~,) ;					\
> > +  .popsection
> > +# endif
> 
> #endif /* DECLARE_SECTION_TBL */
> 
> Btw, what does that macro do? I don't see it used anywhere.

It can be used in asm code to do actually what DEFINE_LINKTABLE() does but now
that I think about it this should then match the name and we'd need one per
standard section, as we have for linker table in C code. I've demo'd this
use in the userspace mockup git tree but with section ranges. In the meantime
I've dropped these macros from this series for now. When we need them we can add
them.

> > + * userspace linker-table tree [1].  This repository can be used for ease of
> > + * testing of extensions and sampling of changes prior to inclusion into Linux,
> > + * it is intended to be kept up to date to match Linux's solution. Contrary to
> 
> Keeping different pieces of code in sync is always a PITA.
> 
> Can we automatically extract the kernel linker tables into a standalone
> userspace pile of C code for experimentation? I.e., something like
> 
> make linker_tables_app

Sure. Will shoot for that.

> > + * enables you to always force compiling of select features that one wishes to
> > + * avoid bit-rot while still enabling you to disable linking feature code into
> > + * the final kernel image if the features have been disabled via Kconfig.
> 
> So this sounds to me like the main reason for linker tables is solving
> the bitrot problem. And I don't think that is the main reason for them,
> is it?

Not for us, it just one added benefit that's possible from it.

> Because we can address the bitrot issue by simply building randconfigs,
> without even touching the kernel. So why do we need those linker tables?

As you noted its described better below.

> > + * Linux's linker tables allows for developers to be selective over where one
> > + * wishes to take advantage of the optional feature of forcing compilation and
> > + * only linking in enabled features.
> > + *
> > + * To use linker tables and to optionally take advantage of avoiding code
> > + * bit-rot, feature code should be implemented in separate C files, and should
> > + * be designed to always be compiled -- they should not be guarded with a C
> > + * code #ifdef CONFIG_FOO statements, consideration must also be taken for
> > + * sub-features which depend on the main CONFIG_FOO option, as they will be
> > + * disabled if they depend on CONFIG_FOO and therefore not compiled. To force
> > + * compilation and only link when features are needed a new optional target
> > + * table-y can be used on Makefiles, documented below.
> 
> Ok, this is more like it. Linker tables actually diminish the Kconfig
> complexity. I'd lead with that.

OK will be sure to clarify all this and thanks for the typo fixes, etc.

> > + * will result with the feature on your binary only if you've enabled
> > + * CONFIG_FOO, however using table-$(CONFIG_FOO) will always force compilation,
> > + * this is why avoiding code bit-rot is an optional fature for Linux linker
> 
> "fature" - please run it through spellchecker.
> 
> Btw, I'm afraid this "table-$(CONFIG" thing might be misused by people
> wanting their stuff to be compile-tested and we'd end up practically
> building an allyesconfig each time.

This should be decided per subsystem maintainer.

> So how can I disable those table-* things from even getting built? Avoid
> using table-y? But then everything declared table-y will be built
> unconditionally. I don't think I like that. :-\

I suppose we could make this configurable... But frankly I would prefer to
instead just document that this use should be carefully considered instead,
and let this be up to the maintainers. We can make it easily configurable so
we can do that later becomes a required, I don't think its needed though
given maintainers should use it only when needed.

> 
> > + * tables.
> > + */
> > +
> > +/**
> > + * DOC: How linker tables simplify inits
> > + *
> > + * Traditionally, we would implement features in C code as follows:
> 
> Ok, so *this* is your main reason for linker tables - not fixing the
> bit-rot problem. The text on the bit-rot problem should come second and
> be the byproduct of linker tables.

Will fix ordering.

> Also, this section here should be the opening section in the document
> explaining linker tables. I'd like to read about what it is first, then
> read what else they're good for.

Sure.

> > + *
> > + *	foo_init();
> > + *
> > + * You'd then have a foo.h which would have:
> > + *
> > + *	#ifdef CONFIG_FOO
> > + *	#else
> > + *	static inline void foo(void) { }
> > + *	#endif
> > + *
> > + * With linker tables this is no longer necessary as your init routines would
> > + * be implicit, you'd instead call:
> > + *
> > + *	call_init_fns();
> > + *
> > + * call_init_fns() would call all functions present in your init table and if
> > + * and only if foo.o gets linked in, then its initialisation function will be
> > + * called, whether you use obj-$(CONFIG_FOO) or table-$(CONFIG_FOO).
> > + *
> > + * The linker script takes care of assembling the tables for us. All of our
> > + * table sections have names of the format SECTION_NAME*.tbl.NAME.N. Here
> 
> The fact that you actually say "tbl" here shows again SECTION_TYPE_TABLES is
> redundant.

I've nuked SECTION_TYPE_TABLES and SECTION_TYPE_RANGES

> > +/**
> > + * DOC: Linker table helpers
> > + *
> > + * These are helpers for linker tables.
> > + */
> 
> I'm assuming those are all needed and we're not adding them just for
> completeness...
> 
> Otherwise, they'll bit-rot. :-))))

The ones we didn't have uses for yet I've nuked now.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-08 15:05       ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-08 15:05 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko

On Fri, Jul 29, 2016 at 12:06:30PM +0200, Borislav Petkov wrote:
> On Fri, Jul 22, 2016 at 02:24:41PM -0700, Luis R. Rodriguez wrote:
> > 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
> > originally based on Michael Brown's iPXE's linker table solution but
> > has been significantly modified to fit Linux's use in its integration.
> 
> ...
> 
> > diff --git a/include/asm-generic/tables.h b/include/asm-generic/tables.h
> > new file mode 100644
> > index 000000000000..5cf655590a19
> > --- /dev/null
> > +++ b/include/asm-generic/tables.h
> > @@ -0,0 +1,70 @@
> > +#ifndef _ASM_GENERIC_TABLES_H_
> > +#define _ASM_GENERIC_TABLES_H_
> > +/*
> > + * Linux linker tables
> > + *
> > + * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
> > + *
> > + * 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/.
> > + */
> > +
> > +#ifdef __KERNEL__
> > +# include <asm/sections.h>
> > +#endif /* __KERNEL__ */
> > +
> > +#define SECTION_TYPE_TABLES	tbl
> 
> What is that for? Section type? Do we have more types or is it useless
> and can go?

We have two types, tables and ranges. But I'll drop that.

> > +
> > +#define SECTION_TBL(section, name, level)				\
> > +	SECTION_TYPE(section, SECTION_TYPE_TABLES, name, level)
> > +
> > +#define SECTION_TBL_ALL(section)					\
> > +	SECTION_TYPE_ALL(section,SECTION_TYPE_TABLES)
> > +
> > +#ifndef section_tbl
> > +# define section_tbl(section, name, level, flags)			\
> > +	 section_type(section, SECTION_TYPE_TABLES, name,		\
> > +		     level, flags)
> 
> That section_type macro is actually saying the following code should
> be in it. Can we make its name have a verb, i.e., something like
> "set_section" to make it more clear?

Sure, thanks changed.

> Also, that type SECTION_TYPE_TABLES looks redundant to me but it
> might start making more sense after I've gone through the rest of the
> series...

I've dropped the type thing.

> > +#endif
> > +
> > +#ifndef section_tbl_any
> > +# define section_tbl_any(section, name, flags)				\
> > +	 section_type(section, SECTION_TYPE_TABLES, name,		\
> > +		     SECTION_ORDER_ANY, flags)
> > +#endif
> > +
> > +#ifndef section_tbl_asmtype
> > +# define section_tbl_asmtype(section, name, level, flags, asmtype)	\
> 
> And here's the confusion: there's "asmtype" but there's also
> SECTION_TYPE_TABLES.
> 
> That asmtype is the *actual* section type in gas speak, i.e., @progbits,
> @note, etc.
> 
> Now *that* should be your type. The SECTION_TYPE_TABLES should be called
> something else or completely gone.

Right, OK dropped and only kept type for this.

> > +	 section_type_asmtype(section, SECTION_TYPE_TABLES, name,	\
> > +			     level, flags, asmtype)
> > +#endif
> > +
> > +#ifndef push_section_tbl
> > +# define push_section_tbl(section, name, level, flags)			\
> > +	 push_section_type(section, SECTION_TYPE_TABLES, name,		\
> > +			  level, flags)
> > +#endif
> > +
> > +#ifndef push_section_tbl_any
> > +# define push_section_tbl_any(section, name, flags)			\
> > +	 push_section_type(section, SECTION_TYPE_TABLES, name,		\
> > +			  SECTION_ORDER_ANY, flags)
> > +#endif
> > +
> > +#if defined(__ASSEMBLER__) || defined(__ASSEMBLY__)
> > +
> > +# ifndef DECLARE_SECTION_TBL
> > +#  define DECLARE_SECTION_TBL(section, name)				\
> > +  push_section_tbl(section, name,,) ;					\
> > +  .globl name ;								\
> > +name: ;									\
> > +  .popsection								\
> > +									\
> > +  push_section_tbl(section, name, ~,) ;					\
> > +  .popsection
> > +# endif
> 
> #endif /* DECLARE_SECTION_TBL */
> 
> Btw, what does that macro do? I don't see it used anywhere.

It can be used in asm code to do actually what DEFINE_LINKTABLE() does but now
that I think about it this should then match the name and we'd need one per
standard section, as we have for linker table in C code. I've demo'd this
use in the userspace mockup git tree but with section ranges. In the meantime
I've dropped these macros from this series for now. When we need them we can add
them.

> > + * userspace linker-table tree [1].  This repository can be used for ease of
> > + * testing of extensions and sampling of changes prior to inclusion into Linux,
> > + * it is intended to be kept up to date to match Linux's solution. Contrary to
> 
> Keeping different pieces of code in sync is always a PITA.
> 
> Can we automatically extract the kernel linker tables into a standalone
> userspace pile of C code for experimentation? I.e., something like
> 
> make linker_tables_app

Sure. Will shoot for that.

> > + * enables you to always force compiling of select features that one wishes to
> > + * avoid bit-rot while still enabling you to disable linking feature code into
> > + * the final kernel image if the features have been disabled via Kconfig.
> 
> So this sounds to me like the main reason for linker tables is solving
> the bitrot problem. And I don't think that is the main reason for them,
> is it?

Not for us, it just one added benefit that's possible from it.

> Because we can address the bitrot issue by simply building randconfigs,
> without even touching the kernel. So why do we need those linker tables?

As you noted its described better below.

> > + * Linux's linker tables allows for developers to be selective over where one
> > + * wishes to take advantage of the optional feature of forcing compilation and
> > + * only linking in enabled features.
> > + *
> > + * To use linker tables and to optionally take advantage of avoiding code
> > + * bit-rot, feature code should be implemented in separate C files, and should
> > + * be designed to always be compiled -- they should not be guarded with a C
> > + * code #ifdef CONFIG_FOO statements, consideration must also be taken for
> > + * sub-features which depend on the main CONFIG_FOO option, as they will be
> > + * disabled if they depend on CONFIG_FOO and therefore not compiled. To force
> > + * compilation and only link when features are needed a new optional target
> > + * table-y can be used on Makefiles, documented below.
> 
> Ok, this is more like it. Linker tables actually diminish the Kconfig
> complexity. I'd lead with that.

OK will be sure to clarify all this and thanks for the typo fixes, etc.

> > + * will result with the feature on your binary only if you've enabled
> > + * CONFIG_FOO, however using table-$(CONFIG_FOO) will always force compilation,
> > + * this is why avoiding code bit-rot is an optional fature for Linux linker
> 
> "fature" - please run it through spellchecker.
> 
> Btw, I'm afraid this "table-$(CONFIG" thing might be misused by people
> wanting their stuff to be compile-tested and we'd end up practically
> building an allyesconfig each time.

This should be decided per subsystem maintainer.

> So how can I disable those table-* things from even getting built? Avoid
> using table-y? But then everything declared table-y will be built
> unconditionally. I don't think I like that. :-\

I suppose we could make this configurable... But frankly I would prefer to
instead just document that this use should be carefully considered instead,
and let this be up to the maintainers. We can make it easily configurable so
we can do that later becomes a required, I don't think its needed though
given maintainers should use it only when needed.

> 
> > + * tables.
> > + */
> > +
> > +/**
> > + * DOC: How linker tables simplify inits
> > + *
> > + * Traditionally, we would implement features in C code as follows:
> 
> Ok, so *this* is your main reason for linker tables - not fixing the
> bit-rot problem. The text on the bit-rot problem should come second and
> be the byproduct of linker tables.

Will fix ordering.

> Also, this section here should be the opening section in the document
> explaining linker tables. I'd like to read about what it is first, then
> read what else they're good for.

Sure.

> > + *
> > + *	foo_init();
> > + *
> > + * You'd then have a foo.h which would have:
> > + *
> > + *	#ifdef CONFIG_FOO
> > + *	#else
> > + *	static inline void foo(void) { }
> > + *	#endif
> > + *
> > + * With linker tables this is no longer necessary as your init routines would
> > + * be implicit, you'd instead call:
> > + *
> > + *	call_init_fns();
> > + *
> > + * call_init_fns() would call all functions present in your init table and if
> > + * and only if foo.o gets linked in, then its initialisation function will be
> > + * called, whether you use obj-$(CONFIG_FOO) or table-$(CONFIG_FOO).
> > + *
> > + * The linker script takes care of assembling the tables for us. All of our
> > + * table sections have names of the format SECTION_NAME*.tbl.NAME.N. Here
> 
> The fact that you actually say "tbl" here shows again SECTION_TYPE_TABLES is
> redundant.

I've nuked SECTION_TYPE_TABLES and SECTION_TYPE_RANGES

> > +/**
> > + * DOC: Linker table helpers
> > + *
> > + * These are helpers for linker tables.
> > + */
> 
> I'm assuming those are all needed and we're not adding them just for
> completeness...
> 
> Otherwise, they'll bit-rot. :-))))

The ones we didn't have uses for yet I've nuked now.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-08 15:05       ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-08 15:05 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker, xen-devel, ak,
	pali.rohar, dvhart, platform-driver-x86, mmarek, linux, jkosina,
	korea.drzix, linux-kbuild, tony.luck, akpm, linux-ia64,
	linux-arm-kernel, linux-sh, sparclinux, catalin.marinas,
	will.deacon, rostedt, jpoimboe

On Fri, Jul 29, 2016 at 12:06:30PM +0200, Borislav Petkov wrote:
> On Fri, Jul 22, 2016 at 02:24:41PM -0700, Luis R. Rodriguez wrote:
> > 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
> > originally based on Michael Brown's iPXE's linker table solution but
> > has been significantly modified to fit Linux's use in its integration.
> 
> ...
> 
> > diff --git a/include/asm-generic/tables.h b/include/asm-generic/tables.h
> > new file mode 100644
> > index 000000000000..5cf655590a19
> > --- /dev/null
> > +++ b/include/asm-generic/tables.h
> > @@ -0,0 +1,70 @@
> > +#ifndef _ASM_GENERIC_TABLES_H_
> > +#define _ASM_GENERIC_TABLES_H_
> > +/*
> > + * Linux linker tables
> > + *
> > + * Copyright (C) 2016 Luis R. Rodriguez <mcgrof@kernel.org>
> > + *
> > + * 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/.
> > + */
> > +
> > +#ifdef __KERNEL__
> > +# include <asm/sections.h>
> > +#endif /* __KERNEL__ */
> > +
> > +#define SECTION_TYPE_TABLES	tbl
> 
> What is that for? Section type? Do we have more types or is it useless
> and can go?

We have two types, tables and ranges. But I'll drop that.

> > +
> > +#define SECTION_TBL(section, name, level)				\
> > +	SECTION_TYPE(section, SECTION_TYPE_TABLES, name, level)
> > +
> > +#define SECTION_TBL_ALL(section)					\
> > +	SECTION_TYPE_ALL(section,SECTION_TYPE_TABLES)
> > +
> > +#ifndef section_tbl
> > +# define section_tbl(section, name, level, flags)			\
> > +	 section_type(section, SECTION_TYPE_TABLES, name,		\
> > +		     level, flags)
> 
> That section_type macro is actually saying the following code should
> be in it. Can we make its name have a verb, i.e., something like
> "set_section" to make it more clear?

Sure, thanks changed.

> Also, that type SECTION_TYPE_TABLES looks redundant to me but it
> might start making more sense after I've gone through the rest of the
> series...

I've dropped the type thing.

> > +#endif
> > +
> > +#ifndef section_tbl_any
> > +# define section_tbl_any(section, name, flags)				\
> > +	 section_type(section, SECTION_TYPE_TABLES, name,		\
> > +		     SECTION_ORDER_ANY, flags)
> > +#endif
> > +
> > +#ifndef section_tbl_asmtype
> > +# define section_tbl_asmtype(section, name, level, flags, asmtype)	\
> 
> And here's the confusion: there's "asmtype" but there's also
> SECTION_TYPE_TABLES.
> 
> That asmtype is the *actual* section type in gas speak, i.e., @progbits,
> @note, etc.
> 
> Now *that* should be your type. The SECTION_TYPE_TABLES should be called
> something else or completely gone.

Right, OK dropped and only kept type for this.

> > +	 section_type_asmtype(section, SECTION_TYPE_TABLES, name,	\
> > +			     level, flags, asmtype)
> > +#endif
> > +
> > +#ifndef push_section_tbl
> > +# define push_section_tbl(section, name, level, flags)			\
> > +	 push_section_type(section, SECTION_TYPE_TABLES, name,		\
> > +			  level, flags)
> > +#endif
> > +
> > +#ifndef push_section_tbl_any
> > +# define push_section_tbl_any(section, name, flags)			\
> > +	 push_section_type(section, SECTION_TYPE_TABLES, name,		\
> > +			  SECTION_ORDER_ANY, flags)
> > +#endif
> > +
> > +#if defined(__ASSEMBLER__) || defined(__ASSEMBLY__)
> > +
> > +# ifndef DECLARE_SECTION_TBL
> > +#  define DECLARE_SECTION_TBL(section, name)				\
> > +  push_section_tbl(section, name,,) ;					\
> > +  .globl name ;								\
> > +name: ;									\
> > +  .popsection								\
> > +									\
> > +  push_section_tbl(section, name, ~,) ;					\
> > +  .popsection
> > +# endif
> 
> #endif /* DECLARE_SECTION_TBL */
> 
> Btw, what does that macro do? I don't see it used anywhere.

It can be used in asm code to do actually what DEFINE_LINKTABLE() does but now
that I think about it this should then match the name and we'd need one per
standard section, as we have for linker table in C code. I've demo'd this
use in the userspace mockup git tree but with section ranges. In the meantime
I've dropped these macros from this series for now. When we need them we can add
them.

> > + * userspace linker-table tree [1].  This repository can be used for ease of
> > + * testing of extensions and sampling of changes prior to inclusion into Linux,
> > + * it is intended to be kept up to date to match Linux's solution. Contrary to
> 
> Keeping different pieces of code in sync is always a PITA.
> 
> Can we automatically extract the kernel linker tables into a standalone
> userspace pile of C code for experimentation? I.e., something like
> 
> make linker_tables_app

Sure. Will shoot for that.

> > + * enables you to always force compiling of select features that one wishes to
> > + * avoid bit-rot while still enabling you to disable linking feature code into
> > + * the final kernel image if the features have been disabled via Kconfig.
> 
> So this sounds to me like the main reason for linker tables is solving
> the bitrot problem. And I don't think that is the main reason for them,
> is it?

Not for us, it just one added benefit that's possible from it.

> Because we can address the bitrot issue by simply building randconfigs,
> without even touching the kernel. So why do we need those linker tables?

As you noted its described better below.

> > + * Linux's linker tables allows for developers to be selective over where one
> > + * wishes to take advantage of the optional feature of forcing compilation and
> > + * only linking in enabled features.
> > + *
> > + * To use linker tables and to optionally take advantage of avoiding code
> > + * bit-rot, feature code should be implemented in separate C files, and should
> > + * be designed to always be compiled -- they should not be guarded with a C
> > + * code #ifdef CONFIG_FOO statements, consideration must also be taken for
> > + * sub-features which depend on the main CONFIG_FOO option, as they will be
> > + * disabled if they depend on CONFIG_FOO and therefore not compiled. To force
> > + * compilation and only link when features are needed a new optional target
> > + * table-y can be used on Makefiles, documented below.
> 
> Ok, this is more like it. Linker tables actually diminish the Kconfig
> complexity. I'd lead with that.

OK will be sure to clarify all this and thanks for the typo fixes, etc.

> > + * will result with the feature on your binary only if you've enabled
> > + * CONFIG_FOO, however using table-$(CONFIG_FOO) will always force compilation,
> > + * this is why avoiding code bit-rot is an optional fature for Linux linker
> 
> "fature" - please run it through spellchecker.
> 
> Btw, I'm afraid this "table-$(CONFIG" thing might be misused by people
> wanting their stuff to be compile-tested and we'd end up practically
> building an allyesconfig each time.

This should be decided per subsystem maintainer.

> So how can I disable those table-* things from even getting built? Avoid
> using table-y? But then everything declared table-y will be built
> unconditionally. I don't think I like that. :-\

I suppose we could make this configurable... But frankly I would prefer to
instead just document that this use should be carefully considered instead,
and let this be up to the maintainers. We can make it easily configurable so
we can do that later becomes a required, I don't think its needed though
given maintainers should use it only when needed.

> 
> > + * tables.
> > + */
> > +
> > +/**
> > + * DOC: How linker tables simplify inits
> > + *
> > + * Traditionally, we would implement features in C code as follows:
> 
> Ok, so *this* is your main reason for linker tables - not fixing the
> bit-rot problem. The text on the bit-rot problem should come second and
> be the byproduct of linker tables.

Will fix ordering.

> Also, this section here should be the opening section in the document
> explaining linker tables. I'd like to read about what it is first, then
> read what else they're good for.

Sure.

> > + *
> > + *	foo_init();
> > + *
> > + * You'd then have a foo.h which would have:
> > + *
> > + *	#ifdef CONFIG_FOO
> > + *	#else
> > + *	static inline void foo(void) { }
> > + *	#endif
> > + *
> > + * With linker tables this is no longer necessary as your init routines would
> > + * be implicit, you'd instead call:
> > + *
> > + *	call_init_fns();
> > + *
> > + * call_init_fns() would call all functions present in your init table and if
> > + * and only if foo.o gets linked in, then its initialisation function will be
> > + * called, whether you use obj-$(CONFIG_FOO) or table-$(CONFIG_FOO).
> > + *
> > + * The linker script takes care of assembling the tables for us. All of our
> > + * table sections have names of the format SECTION_NAME*.tbl.NAME.N. Here
> 
> The fact that you actually say "tbl" here shows again SECTION_TYPE_TABLES is
> redundant.

I've nuked SECTION_TYPE_TABLES and SECTION_TYPE_RANGES

> > +/**
> > + * DOC: Linker table helpers
> > + *
> > + * These are helpers for linker tables.
> > + */
> 
> I'm assuming those are all needed and we're not adding them just for
> completeness...
> 
> Otherwise, they'll bit-rot. :-))))

The ones we didn't have uses for yet I've nuked now.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-08-08 15:05       ` Luis R. Rodriguez
  (?)
@ 2016-08-09  3:55         ` Borislav Petkov
  -1 siblings, 0 replies; 176+ messages in thread
From: Borislav Petkov @ 2016-08-09  3:55 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, linux, mhiramat, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-

On Mon, Aug 08, 2016 at 05:05:39PM +0200, Luis R. Rodriguez wrote:
> > So how can I disable those table-* things from even getting built? Avoid
> > using table-y? But then everything declared table-y will be built
> > unconditionally. I don't think I like that. :-\
> 
> I suppose we could make this configurable... But frankly I would prefer to
> instead just document that this use should be carefully considered instead,
> and let this be up to the maintainers. We can make it easily configurable so
> we can do that later becomes a required, I don't think its needed though
> given maintainers should use it only when needed.

You know how maintainers are just people, right? At least in most cases :-)

I think it would be better if it were machine-enforceable somehow.
Maybe allow it only for core code and have a single, per-arch file
arch/x86/linker_tables or so where all those statements are collected
and can be eyeballed by more people. Dunno, just trying to think of
something here...

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-09  3:55         ` Borislav Petkov
  0 siblings, 0 replies; 176+ messages in thread
From: Borislav Petkov @ 2016-08-09  3:55 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, linux, mhiramat, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-

On Mon, Aug 08, 2016 at 05:05:39PM +0200, Luis R. Rodriguez wrote:
> > So how can I disable those table-* things from even getting built? Avoid
> > using table-y? But then everything declared table-y will be built
> > unconditionally. I don't think I like that. :-\
> 
> I suppose we could make this configurable... But frankly I would prefer to
> instead just document that this use should be carefully considered instead,
> and let this be up to the maintainers. We can make it easily configurable so
> we can do that later becomes a required, I don't think its needed though
> given maintainers should use it only when needed.

You know how maintainers are just people, right? At least in most cases :-)

I think it would be better if it were machine-enforceable somehow.
Maybe allow it only for core code and have a single, per-arch file
arch/x86/linker_tables or so where all those statements are collected
and can be eyeballed by more people. Dunno, just trying to think of
something here...

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-09  3:55         ` Borislav Petkov
  0 siblings, 0 replies; 176+ messages in thread
From: Borislav Petkov @ 2016-08-09  3:55 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, linux, mhiramat, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe

On Mon, Aug 08, 2016 at 05:05:39PM +0200, Luis R. Rodriguez wrote:
> > So how can I disable those table-* things from even getting built? Avoid
> > using table-y? But then everything declared table-y will be built
> > unconditionally. I don't think I like that. :-\
> 
> I suppose we could make this configurable... But frankly I would prefer to
> instead just document that this use should be carefully considered instead,
> and let this be up to the maintainers. We can make it easily configurable so
> we can do that later becomes a required, I don't think its needed though
> given maintainers should use it only when needed.

You know how maintainers are just people, right? At least in most cases :-)

I think it would be better if it were machine-enforceable somehow.
Maybe allow it only for core code and have a single, per-arch file
arch/x86/linker_tables or so where all those statements are collected
and can be eyeballed by more people. Dunno, just trying to think of
something here...

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
  2016-07-22 21:24 ` Luis R. Rodriguez
  (?)
@ 2016-08-09 14:24   ` One Thousand Gnomes
  -1 siblings, 0 replies; 176+ messages in thread
From: One Thousand Gnomes @ 2016-08-09 14:24 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6, x86, luto, keescook, torvalds, gregkh, rusty, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel

> table development go under copyleft-next, Rusty recently asked for code
> to go in prior to the license tag being added denoting this license as
> GPL-compatible [3] -- I had noted in the patch submission which annotated
> copyleft-next's compatibility to GPLv2 that copyleft-next is the license
> of choice for ongoing kernel development on my end [4]. If this is
> objectionable I'm happy to change it to GPLv2 however I'd like a reason
> provided as I've gone through all possible channels to ensure this is kosher,
> including vetting by 3 attorneys now, 2 at SUSE.

You don't need a new tag, you can use "GPL" or "GPL and additional
rights". In fact you don't want any other tag because when combined with
the kernel it is GPLv2 anyway because the only way the two are fully
compatible is for the kernel community to license the derived work under
the GPL.

The second reason you must use the GPL or GPL with additional tag is
clause 8. We don't want anyone to create a module under your licence,
claim it is "open source" then fifteen years later release the module in
binary only form still with a tag saying "copyleft-next" which we treat
as GPL compatible. It's the same reason we don't have a BSD tag but use
"GPL with additional rights" to stop abuse of the module tags.

However you need to clarify the licence first I think. Linux is GPLv2,
your document only allows use of GPL with "GPL" works - not GPL v2 works ?

As PS: btw your licence is kind of weird. I can combine it with GPL work,
make it GPL therefore, and then use the GPL rights to remove the bits I
added thereby meaning I have your exact original work under the GPL. Not
sure how it's intended to work ?

It would also be good if someone clarified whether 6 and 7 are intended
to combine so you can take contributed patches and put them in your own
proprietary version. As a non-lawyer the intent is not clear at all.

Alan

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-08-09 14:24   ` One Thousand Gnomes
  0 siblings, 0 replies; 176+ messages in thread
From: One Thousand Gnomes @ 2016-08-09 14:24 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6, x86, luto, keescook, torvalds, gregkh, rusty, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel

> table development go under copyleft-next, Rusty recently asked for code
> to go in prior to the license tag being added denoting this license as
> GPL-compatible [3] -- I had noted in the patch submission which annotated
> copyleft-next's compatibility to GPLv2 that copyleft-next is the license
> of choice for ongoing kernel development on my end [4]. If this is
> objectionable I'm happy to change it to GPLv2 however I'd like a reason
> provided as I've gone through all possible channels to ensure this is kosher,
> including vetting by 3 attorneys now, 2 at SUSE.

You don't need a new tag, you can use "GPL" or "GPL and additional
rights". In fact you don't want any other tag because when combined with
the kernel it is GPLv2 anyway because the only way the two are fully
compatible is for the kernel community to license the derived work under
the GPL.

The second reason you must use the GPL or GPL with additional tag is
clause 8. We don't want anyone to create a module under your licence,
claim it is "open source" then fifteen years later release the module in
binary only form still with a tag saying "copyleft-next" which we treat
as GPL compatible. It's the same reason we don't have a BSD tag but use
"GPL with additional rights" to stop abuse of the module tags.

However you need to clarify the licence first I think. Linux is GPLv2,
your document only allows use of GPL with "GPL" works - not GPL v2 works ?

As PS: btw your licence is kind of weird. I can combine it with GPL work,
make it GPL therefore, and then use the GPL rights to remove the bits I
added thereby meaning I have your exact original work under the GPL. Not
sure how it's intended to work ?

It would also be good if someone clarified whether 6 and 7 are intended
to combine so you can take contributed patches and put them in your own
proprietary version. As a non-lawyer the intent is not clear at all.

Alan

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-08-09 14:24   ` One Thousand Gnomes
  0 siblings, 0 replies; 176+ messages in thread
From: One Thousand Gnomes @ 2016-08-09 14:24 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6, x86, luto, keescook, torvalds, gregkh, rusty, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe

> table development go under copyleft-next, Rusty recently asked for code
> to go in prior to the license tag being added denoting this license as
> GPL-compatible [3] -- I had noted in the patch submission which annotated
> copyleft-next's compatibility to GPLv2 that copyleft-next is the license
> of choice for ongoing kernel development on my end [4]. If this is
> objectionable I'm happy to change it to GPLv2 however I'd like a reason
> provided as I've gone through all possible channels to ensure this is kosher,
> including vetting by 3 attorneys now, 2 at SUSE.

You don't need a new tag, you can use "GPL" or "GPL and additional
rights". In fact you don't want any other tag because when combined with
the kernel it is GPLv2 anyway because the only way the two are fully
compatible is for the kernel community to license the derived work under
the GPL.

The second reason you must use the GPL or GPL with additional tag is
clause 8. We don't want anyone to create a module under your licence,
claim it is "open source" then fifteen years later release the module in
binary only form still with a tag saying "copyleft-next" which we treat
as GPL compatible. It's the same reason we don't have a BSD tag but use
"GPL with additional rights" to stop abuse of the module tags.

However you need to clarify the licence first I think. Linux is GPLv2,
your document only allows use of GPL with "GPL" works - not GPL v2 works ?

As PS: btw your licence is kind of weird. I can combine it with GPL work,
make it GPL therefore, and then use the GPL rights to remove the bits I
added thereby meaning I have your exact original work under the GPL. Not
sure how it's intended to work ?

It would also be good if someone clarified whether 6 and 7 are intended
to combine so you can take contributed patches and put them in your own
proprietary version. As a non-lawyer the intent is not clear at all.

Alan

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
  2016-08-09 14:24   ` One Thousand Gnomes
  (?)
@ 2016-08-09 16:09     ` James Bottomley
  -1 siblings, 0 replies; 176+ messages in thread
From: James Bottomley @ 2016-08-09 16:09 UTC (permalink / raw)
  To: One Thousand Gnomes, Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6, x86, luto, keescook, torvalds, gregkh, rusty, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel

On Tue, 2016-08-09 at 15:24 +0100, One Thousand Gnomes wrote:
> > table development go under copyleft-next, Rusty recently asked for 
> > code to go in prior to the license tag being added denoting this 
> > license as GPL-compatible [3] -- I had noted in the patch 
> > submission which annotated copyleft-next's compatibility to GPLv2 
> > that copyleft-next is the license of choice for ongoing kernel 
> > development on my end [4]. If this is objectionable I'm happy to 
> > change it to GPLv2 however I'd like a reason provided as I've gone 
> > through all possible channels to ensure this is kosher, including
> > vetting by 3 attorneys now, 2 at SUSE.
> 
> You don't need a new tag, you can use "GPL" or "GPL and additional
> rights". In fact you don't want any other tag because when combined
>  with the kernel it is GPLv2 anyway because the only way the two are 
> fully compatible is for the kernel community to license the derived 
> work under the GPL.

This is the module tag ... it says what licence the module is under,
not the licence for the module combined with the kernel, which is
always GPLv2 because the stricter licence rules.

> The second reason you must use the GPL or GPL with additional tag is
> clause 8. We don't want anyone to create a module under your licence,
> claim it is "open source" then fifteen years later release the module 
> in binary only form still with a tag saying "copyleft-next" which we
> treat as GPL compatible. It's the same reason we don't have a BSD tag 
> but use "GPL with additional rights" to stop abuse of the module
> tags.

I don't follow you here.  We do have separate Dual licence tags. Dual
BSD/GPL allows me to do this today, without waiting fifteen years.  I
think you're conflating two issues:

   1. The licence of the actual module, which must be compatible with the
      kernel to do an insmod.  This is actually what MODULE_LICENSE
      declares
   2. The conditions the creation of the combined work imposes on me

It's the latter, even in the case of Dual BSD/GPL which still requires
me to release source code, so the combination with the kernel forces
GPL conditions even in the case of a BSD module (which is otherwise
compatible) and even after 15 years of this copyleft-next.

The point is: I can create a pure BSD module.  You can pick it up and
put it into the kernel source as Dual BSD/GPL, because BSD allows this,
but I'm still free to create binary only versions under BSD (as long as
they're for something other than inserting into Linux).  However, if I
want my binary only modules to be combined with Linux, I have to follow
GPLv2 compliance because GPLv2 becomes the ruling licence of the
combination.  The same would apply to this copyleft-next, even after 15
years.

> However you need to clarify the licence first I think. Linux is 
> GPLv2, your document only allows use of GPL with "GPL" works - not 
> GPL v2 works ?

A reasonable person would take GPL to mean any version of GPL.

> As PS: btw your licence is kind of weird. I can combine it with GPL 
> work, make it GPL therefore, and then use the GPL rights to remove 
> the bits I added thereby meaning I have your exact original work 
> under the GPL. Not sure how it's intended to work ?

What you describe is how it's always worked.  You may always distribute
a compatibly licensed piece of code under the stricter licence. 
 Additional permissions are always strippable in GPLv3 terms.

> It would also be good if someone clarified whether 6 and 7 are 
> intended to combine so you can take contributed patches and put them 
> in your own proprietary version. As a non-lawyer the intent is not
> clear at all.

The US copyright office defines a copyright work as anything which is
"an original work of authorship fixed in any tangible medium of
expression".  That means any change to an existing work (i.e. by a
patch) which contains enough originality to make the changed work
distinct from the old work is ipso facto a new work.  under copyright
-next this new work has a sunset 15 years from its creation by
combination, not 15 years from the original.  This means a constantly
updated work never sunsets.  Sure, you can go back 15 years and claim
the code at that time has passed into the public domain but you can't
do that if you also want the benefit of later changes.

James


^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-08-09 16:09     ` James Bottomley
  0 siblings, 0 replies; 176+ messages in thread
From: James Bottomley @ 2016-08-09 16:09 UTC (permalink / raw)
  To: One Thousand Gnomes, Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6, x86, luto, keescook, torvalds, gregkh, rusty, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel

On Tue, 2016-08-09 at 15:24 +0100, One Thousand Gnomes wrote:
> > table development go under copyleft-next, Rusty recently asked for 
> > code to go in prior to the license tag being added denoting this 
> > license as GPL-compatible [3] -- I had noted in the patch 
> > submission which annotated copyleft-next's compatibility to GPLv2 
> > that copyleft-next is the license of choice for ongoing kernel 
> > development on my end [4]. If this is objectionable I'm happy to 
> > change it to GPLv2 however I'd like a reason provided as I've gone 
> > through all possible channels to ensure this is kosher, including
> > vetting by 3 attorneys now, 2 at SUSE.
> 
> You don't need a new tag, you can use "GPL" or "GPL and additional
> rights". In fact you don't want any other tag because when combined
>  with the kernel it is GPLv2 anyway because the only way the two are 
> fully compatible is for the kernel community to license the derived 
> work under the GPL.

This is the module tag ... it says what licence the module is under,
not the licence for the module combined with the kernel, which is
always GPLv2 because the stricter licence rules.

> The second reason you must use the GPL or GPL with additional tag is
> clause 8. We don't want anyone to create a module under your licence,
> claim it is "open source" then fifteen years later release the module 
> in binary only form still with a tag saying "copyleft-next" which we
> treat as GPL compatible. It's the same reason we don't have a BSD tag 
> but use "GPL with additional rights" to stop abuse of the module
> tags.

I don't follow you here.  We do have separate Dual licence tags. Dual
BSD/GPL allows me to do this today, without waiting fifteen years.  I
think you're conflating two issues:

   1. The licence of the actual module, which must be compatible with the
      kernel to do an insmod.  This is actually what MODULE_LICENSE
      declares
   2. The conditions the creation of the combined work imposes on me

It's the latter, even in the case of Dual BSD/GPL which still requires
me to release source code, so the combination with the kernel forces
GPL conditions even in the case of a BSD module (which is otherwise
compatible) and even after 15 years of this copyleft-next.

The point is: I can create a pure BSD module.  You can pick it up and
put it into the kernel source as Dual BSD/GPL, because BSD allows this,
but I'm still free to create binary only versions under BSD (as long as
they're for something other than inserting into Linux).  However, if I
want my binary only modules to be combined with Linux, I have to follow
GPLv2 compliance because GPLv2 becomes the ruling licence of the
combination.  The same would apply to this copyleft-next, even after 15
years.

> However you need to clarify the licence first I think. Linux is 
> GPLv2, your document only allows use of GPL with "GPL" works - not 
> GPL v2 works ?

A reasonable person would take GPL to mean any version of GPL.

> As PS: btw your licence is kind of weird. I can combine it with GPL 
> work, make it GPL therefore, and then use the GPL rights to remove 
> the bits I added thereby meaning I have your exact original work 
> under the GPL. Not sure how it's intended to work ?

What you describe is how it's always worked.  You may always distribute
a compatibly licensed piece of code under the stricter licence. 
 Additional permissions are always strippable in GPLv3 terms.

> It would also be good if someone clarified whether 6 and 7 are 
> intended to combine so you can take contributed patches and put them 
> in your own proprietary version. As a non-lawyer the intent is not
> clear at all.

The US copyright office defines a copyright work as anything which is
"an original work of authorship fixed in any tangible medium of
expression".  That means any change to an existing work (i.e. by a
patch) which contains enough originality to make the changed work
distinct from the old work is ipso facto a new work.  under copyright
-next this new work has a sunset 15 years from its creation by
combination, not 15 years from the original.  This means a constantly
updated work never sunsets.  Sure, you can go back 15 years and claim
the code at that time has passed into the public domain but you can't
do that if you also want the benefit of later changes.

James


^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-08-09 16:09     ` James Bottomley
  0 siblings, 0 replies; 176+ messages in thread
From: James Bottomley @ 2016-08-09 16:09 UTC (permalink / raw)
  To: One Thousand Gnomes, Luis R. Rodriguez
  Cc: hpa, tglx, mingo, bp, linux, mhiramat, masami.hiramatsu.pt,
	jbaron, heiko.carstens, ananth, anil.s.keshavamurthy, davem,
	realmz6, x86, luto, keescook, torvalds, gregkh, rusty, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe

On Tue, 2016-08-09 at 15:24 +0100, One Thousand Gnomes wrote:
> > table development go under copyleft-next, Rusty recently asked for 
> > code to go in prior to the license tag being added denoting this 
> > license as GPL-compatible [3] -- I had noted in the patch 
> > submission which annotated copyleft-next's compatibility to GPLv2 
> > that copyleft-next is the license of choice for ongoing kernel 
> > development on my end [4]. If this is objectionable I'm happy to 
> > change it to GPLv2 however I'd like a reason provided as I've gone 
> > through all possible channels to ensure this is kosher, including
> > vetting by 3 attorneys now, 2 at SUSE.
> 
> You don't need a new tag, you can use "GPL" or "GPL and additional
> rights". In fact you don't want any other tag because when combined
>  with the kernel it is GPLv2 anyway because the only way the two are 
> fully compatible is for the kernel community to license the derived 
> work under the GPL.

This is the module tag ... it says what licence the module is under,
not the licence for the module combined with the kernel, which is
always GPLv2 because the stricter licence rules.

> The second reason you must use the GPL or GPL with additional tag is
> clause 8. We don't want anyone to create a module under your licence,
> claim it is "open source" then fifteen years later release the module 
> in binary only form still with a tag saying "copyleft-next" which we
> treat as GPL compatible. It's the same reason we don't have a BSD tag 
> but use "GPL with additional rights" to stop abuse of the module
> tags.

I don't follow you here.  We do have separate Dual licence tags. Dual
BSD/GPL allows me to do this today, without waiting fifteen years.  I
think you're conflating two issues:

   1. The licence of the actual module, which must be compatible with the
      kernel to do an insmod.  This is actually what MODULE_LICENSE
      declares
   2. The conditions the creation of the combined work imposes on me

It's the latter, even in the case of Dual BSD/GPL which still requires
me to release source code, so the combination with the kernel forces
GPL conditions even in the case of a BSD module (which is otherwise
compatible) and even after 15 years of this copyleft-next.

The point is: I can create a pure BSD module.  You can pick it up and
put it into the kernel source as Dual BSD/GPL, because BSD allows this,
but I'm still free to create binary only versions under BSD (as long as
they're for something other than inserting into Linux).  However, if I
want my binary only modules to be combined with Linux, I have to follow
GPLv2 compliance because GPLv2 becomes the ruling licence of the
combination.  The same would apply to this copyleft-next, even after 15
years.

> However you need to clarify the licence first I think. Linux is 
> GPLv2, your document only allows use of GPL with "GPL" works - not 
> GPL v2 works ?

A reasonable person would take GPL to mean any version of GPL.

> As PS: btw your licence is kind of weird. I can combine it with GPL 
> work, make it GPL therefore, and then use the GPL rights to remove 
> the bits I added thereby meaning I have your exact original work 
> under the GPL. Not sure how it's intended to work ?

What you describe is how it's always worked.  You may always distribute
a compatibly licensed piece of code under the stricter licence. 
 Additional permissions are always strippable in GPLv3 terms.

> It would also be good if someone clarified whether 6 and 7 are 
> intended to combine so you can take contributed patches and put them 
> in your own proprietary version. As a non-lawyer the intent is not
> clear at all.

The US copyright office defines a copyright work as anything which is
"an original work of authorship fixed in any tangible medium of
expression".  That means any change to an existing work (i.e. by a
patch) which contains enough originality to make the changed work
distinct from the old work is ipso facto a new work.  under copyright
-next this new work has a sunset 15 years from its creation by
combination, not 15 years from the original.  This means a constantly
updated work never sunsets.  Sure, you can go back 15 years and claim
the code at that time has passed into the public domain but you can't
do that if you also want the benefit of later changes.

James


^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
  2016-08-09 14:24   ` One Thousand Gnomes
  (?)
@ 2016-08-09 16:48     ` Richard Fontana
  -1 siblings, 0 replies; 176+ messages in thread
From: Richard Fontana @ 2016-08-09 16:48 UTC (permalink / raw)
  To: One Thousand Gnomes
  Cc: linux-ia64, jkosina, benh, ming.lei, heiko.carstens,
	platform-driver-x86, paul.gortmaker, hpa, masami.hiramatsu.pt,
	linux-arch, sparclinux, xen-devel, linux, linux-sh, will.deacon,
	korea.drzix, x86, anil.s.keshavamurthy, torvalds, mingo,
	linux-arm-kernel, catalin.marinas, dvhart, david.vrabel,
	pali.rohar, keescook, arnd, realmz6, linux, rusty, rostedt,
	christopher.denicolo, jbaron, ananth, bp, jpoimboe

On Tue, Aug 09, 2016 at 03:24:29PM +0100, One Thousand Gnomes wrote:
> It would also be good if someone clarified whether 6 and 7 are intended
> to combine so you can take contributed patches and put them in your own
> proprietary version. As a non-lawyer the intent is not clear at all.

6 and 7 aren't intended to combine; they address separate issues and
circumstances.

Richard

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-08-09 16:48     ` Richard Fontana
  0 siblings, 0 replies; 176+ messages in thread
From: Richard Fontana @ 2016-08-09 16:48 UTC (permalink / raw)
  To: One Thousand Gnomes
  Cc: linux-ia64, jkosina, benh, ming.lei, heiko.carstens,
	platform-driver-x86, paul.gortmaker, hpa, masami.hiramatsu.pt,
	linux-arch, sparclinux, xen-devel, linux, linux-sh, will.deacon,
	korea.drzix, x86, anil.s.keshavamurthy, torvalds, mingo,
	linux-arm-kernel, catalin.marinas, dvhart, david.vrabel,
	pali.rohar, keescook, arnd, realmz6, linux, rusty, rostedt,
	christopher.denicolo, jbaron, ananth, bp, jpoimboe

On Tue, Aug 09, 2016 at 03:24:29PM +0100, One Thousand Gnomes wrote:
> It would also be good if someone clarified whether 6 and 7 are intended
> to combine so you can take contributed patches and put them in your own
> proprietary version. As a non-lawyer the intent is not clear at all.

6 and 7 aren't intended to combine; they address separate issues and
circumstances.

Richard

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-08-09 16:48     ` Richard Fontana
  0 siblings, 0 replies; 176+ messages in thread
From: Richard Fontana @ 2016-08-09 16:48 UTC (permalink / raw)
  To: One Thousand Gnomes
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, alan, dwmw2, arnd, ming.lei, linux-arch,
	benh, ananth, pebolle, ciaran.farrell, christopher.denicolo,
	david.vrabel, konrad.wilk, mcb30, jgross, andrew.cooper3,
	andriy.shevchenko, paul.gortmaker, xen-devel, ak, pali.rohar,
	dvhart, platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe

On Tue, Aug 09, 2016 at 03:24:29PM +0100, One Thousand Gnomes wrote:
> It would also be good if someone clarified whether 6 and 7 are intended
> to combine so you can take contributed patches and put them in your own
> proprietary version. As a non-lawyer the intent is not clear at all.

6 and 7 aren't intended to combine; they address separate issues and
circumstances.

Richard

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
  2016-08-09 14:24   ` One Thousand Gnomes
  (?)
@ 2016-08-09 16:52     ` Richard Fontana
  -1 siblings, 0 replies; 176+ messages in thread
From: Richard Fontana @ 2016-08-09 16:52 UTC (permalink / raw)
  To: One Thousand Gnomes
  Cc: linux-ia64, jkosina, benh, ming.lei, heiko.carstens,
	platform-driver-x86, paul.gortmaker, hpa, masami.hiramatsu.pt,
	linux-arch, sparclinux, xen-devel, linux, linux-sh, will.deacon,
	korea.drzix, x86, anil.s.keshavamurthy, torvalds, mingo,
	linux-arm-kernel, catalin.marinas, dvhart, david.vrabel,
	pali.rohar, keescook, arnd, realmz6, linux, rusty, rostedt,
	christopher.denicolo, jbaron, ananth, bp, jpoimboe

On Tue, Aug 09, 2016 at 03:24:29PM +0100, One Thousand Gnomes wrote:
> However you need to clarify the licence first I think. Linux is GPLv2,
> your document only allows use of GPL with "GPL" works - not GPL v2 works ?

The license defines "GPL" as "a version of the GNU General Public
License or the GNU Affero General Public License."

Richard


^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-08-09 16:52     ` Richard Fontana
  0 siblings, 0 replies; 176+ messages in thread
From: Richard Fontana @ 2016-08-09 16:52 UTC (permalink / raw)
  To: One Thousand Gnomes
  Cc: linux-ia64, jkosina, benh, ming.lei, heiko.carstens,
	platform-driver-x86, paul.gortmaker, hpa, masami.hiramatsu.pt,
	linux-arch, sparclinux, xen-devel, linux, linux-sh, will.deacon,
	korea.drzix, x86, anil.s.keshavamurthy, torvalds, mingo,
	linux-arm-kernel, catalin.marinas, dvhart, david.vrabel,
	pali.rohar, keescook, arnd, realmz6, linux, rusty, rostedt,
	christopher.denicolo, jbaron, ananth, bp, jpoimboe

On Tue, Aug 09, 2016 at 03:24:29PM +0100, One Thousand Gnomes wrote:
> However you need to clarify the licence first I think. Linux is GPLv2,
> your document only allows use of GPL with "GPL" works - not GPL v2 works ?

The license defines "GPL" as "a version of the GNU General Public
License or the GNU Affero General Public License."

Richard


_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-08-09 16:52     ` Richard Fontana
  0 siblings, 0 replies; 176+ messages in thread
From: Richard Fontana @ 2016-08-09 16:52 UTC (permalink / raw)
  To: One Thousand Gnomes
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, bp, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, alan, dwmw2, arnd, ming.lei, linux-arch,
	benh, ananth, pebolle, ciaran.farrell, christopher.denicolo,
	david.vrabel, konrad.wilk, mcb30, jgross, andrew.cooper3,
	andriy.shevchenko, paul.gortmaker, xen-devel, ak, pali.rohar,
	dvhart, platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe

On Tue, Aug 09, 2016 at 03:24:29PM +0100, One Thousand Gnomes wrote:
> However you need to clarify the licence first I think. Linux is GPLv2,
> your document only allows use of GPL with "GPL" works - not GPL v2 works ?

The license defines "GPL" as "a version of the GNU General Public
License or the GNU Affero General Public License."

Richard


^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-08-10  4:51       ` Andy Lutomirski
  0 siblings, 0 replies; 176+ messages in thread
From: Andy Lutomirski @ 2016-08-10  4:51 UTC (permalink / raw)
  To: James Bottomley
  Cc: One Thousand Gnomes, linux-ia64, realmz6, linux-sh, benh,
	ming.lei, heiko.carstens, linux, platform-driver-x86,
	paul.gortmaker, hpa, masami.hiramatsu.pt, linux-arch, sparclinux,
	xen-devel, linux, x86, anil.s.keshavamurthy, fontana, mingo,
	catalin.marinas, dvhart, dwmw2, mhiramat, rusty, keescook, arnd,
	linux-kbuild, will.deacon, pali.rohar, rostedt,
	christopher.denicolo, jbaron, ananth, ciaran.farrell


[-- Attachment #1.1: Type: text/plain, Size: 1335 bytes --]

On Aug 9, 2016 7:09 PM, "James Bottomley" <
James.Bottomley@hansenpartnership.com> wrote:
>
> On Tue, 2016-08-09 at 15:24 +0100, One Thousand Gnomes wrote:
> > > table development go under copyleft-next, Rusty recently asked for
> > > code to go in prior to the license tag being added denoting this
> > > license as GPL-compatible [3] -- I had noted in the patch
> > > submission which annotated copyleft-next's compatibility to GPLv2
> > > that copyleft-next is the license of choice for ongoing kernel
> > > development on my end [4]. If this is objectionable I'm happy to
> > > change it to GPLv2 however I'd like a reason provided as I've gone
> > > through all possible channels to ensure this is kosher, including
> > > vetting by 3 attorneys now, 2 at SUSE.
> >
> > You don't need a new tag, you can use "GPL" or "GPL and additional
> > rights". In fact you don't want any other tag because when combined
> >  with the kernel it is GPLv2 anyway because the only way the two are
> > fully compatible is for the kernel community to license the derived
> > work under the GPL.
>
> This is the module tag ... it says what licence the module is under,
> not the licence for the module combined with the kernel, which is
> always GPLv2 because the stricter licence rules.

Then why isn't "BSD" in the license_is_gpl_compatible list?

[-- Attachment #1.2: Type: text/html, Size: 1762 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-08-10  4:51       ` Andy Lutomirski
  0 siblings, 0 replies; 176+ messages in thread
From: Andy Lutomirski @ 2016-08-10  4:51 UTC (permalink / raw)
  To: James Bottomley
  Cc: benh, masami.hiramatsu.pt, linux, linux-kbuild, linux-sh,
	torvalds, akpm, dwmw2, xen-devel, Luis R. Rodriguez,
	anil.s.keshavamurthy, will.deacon, linux-ia64, x86, korea.drzix,
	mingo, andrew.cooper3, jgross, tglx, keescook, ananth, jpoimboe,
	rostedt, hpa, arnd, davem, One Thousand Gnomes,
	platform-driver-x86, jkosina, david.vrabel, realmz6, fontana,
	konrad.wilk, ananth, paul.gortmaker, pali.rohar, ak, pebolle,
	jbaron, mmarek, rusty, tony.luck, catalin.marinas, dvhart,
	linux-arm-kernel, ming.lei, linux, andriy.shevchenko,
	christopher.denicolo, linux-arch, mcb30, heiko.carstens, gregkh,
	mhiramat, ciaran.farrell, bp, sparclinux, alan

[-- Attachment #1: Type: text/plain, Size: 1335 bytes --]

On Aug 9, 2016 7:09 PM, "James Bottomley" <
James.Bottomley@hansenpartnership.com> wrote:
>
> On Tue, 2016-08-09 at 15:24 +0100, One Thousand Gnomes wrote:
> > > table development go under copyleft-next, Rusty recently asked for
> > > code to go in prior to the license tag being added denoting this
> > > license as GPL-compatible [3] -- I had noted in the patch
> > > submission which annotated copyleft-next's compatibility to GPLv2
> > > that copyleft-next is the license of choice for ongoing kernel
> > > development on my end [4]. If this is objectionable I'm happy to
> > > change it to GPLv2 however I'd like a reason provided as I've gone
> > > through all possible channels to ensure this is kosher, including
> > > vetting by 3 attorneys now, 2 at SUSE.
> >
> > You don't need a new tag, you can use "GPL" or "GPL and additional
> > rights". In fact you don't want any other tag because when combined
> >  with the kernel it is GPLv2 anyway because the only way the two are
> > fully compatible is for the kernel community to license the derived
> > work under the GPL.
>
> This is the module tag ... it says what licence the module is under,
> not the licence for the module combined with the kernel, which is
> always GPLv2 because the stricter licence rules.

Then why isn't "BSD" in the license_is_gpl_compatible list?

[-- Attachment #2: Type: text/html, Size: 1762 bytes --]

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
  2016-08-09 16:09     ` James Bottomley
  (?)
@ 2016-08-10 17:03       ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-10 17:03 UTC (permalink / raw)
  To: James Bottomley
  Cc: One Thousand Gnomes, linux-ia64, jkosina, benh, ming.lei,
	heiko.carstens, platform-driver-x86, paul.gortmaker, hpa,
	masami.hiramatsu.pt, linux-arch, msalter, sparclinux, xen-devel,
	linux, linux-sh, will.deacon, korea.drzix, x86,
	anil.s.keshavamurthy, fontana, mingo, linux-arm-kernel,
	catalin.marinas, dvhart, dwmw2, david.vrabel, pali.rohar,
	keescook, arnd, realmz6, a-jacquiot, linux, rusty, rostedt,
	chris

On Tue, Aug 09, 2016 at 09:09:07AM -0700, James Bottomley wrote:
> On Tue, 2016-08-09 at 15:24 +0100, One Thousand Gnomes wrote:
> > > table development go under copyleft-next, Rusty recently asked for 
> > > code to go in prior to the license tag being added denoting this 
> > > license as GPL-compatible [3] -- I had noted in the patch 
> > > submission which annotated copyleft-next's compatibility to GPLv2 
> > > that copyleft-next is the license of choice for ongoing kernel 
> > > development on my end [4]. If this is objectionable I'm happy to 
> > > change it to GPLv2 however I'd like a reason provided as I've gone 
> > > through all possible channels to ensure this is kosher, including
> > > vetting by 3 attorneys now, 2 at SUSE.
> > 
> > You don't need a new tag, you can use "GPL" or "GPL and additional
> > rights". In fact you don't want any other tag because when combined
> >  with the kernel it is GPLv2 anyway because the only way the two are 
> > fully compatible is for the kernel community to license the derived 
> > work under the GPL.
> 
> This is the module tag ... it says what licence the module is under,
> not the licence for the module combined with the kernel, which is
> always GPLv2 because the stricter licence rules.

As per Linus' recommendations [0] if I add a module I'll be using
MODULE_LICENSE("GPL") if using copyleft-next. Either way this series
didn't add a module yet so no need for that yet, but it does use
copyleft-next in headers / C code.

[0] https://lkml.kernel.org/r/CA+55aFyhxcvD+q7tp+-yrSFDKfR0mOHgyEAe=f_94aKLsOu0Og@mail.gmail.com

> However, if I
> want my binary only modules to be combined with Linux, I have to follow
> GPLv2 compliance because GPLv2 becomes the ruling licence of the
> combination.  The same would apply to this copyleft-next, even after 15
> years.

And this what really matters here.

> The US copyright office defines a copyright work as anything which is
> "an original work of authorship fixed in any tangible medium of
> expression".  That means any change to an existing work (i.e. by a
> patch) which contains enough originality to make the changed work
> distinct from the old work is ipso facto a new work.  under copyright
> -next this new work has a sunset 15 years from its creation by
> combination, not 15 years from the original.  This means a constantly
> updated work never sunsets.  Sure, you can go back 15 years and claim
> the code at that time has passed into the public domain but you can't
> do that if you also want the benefit of later changes.

Agreed.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-08-10 17:03       ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-10 17:03 UTC (permalink / raw)
  To: James Bottomley
  Cc: One Thousand Gnomes, linux-ia64, jkosina, benh, ming.lei,
	heiko.carstens, platform-driver-x86, paul.gortmaker, hpa,
	masami.hiramatsu.pt, linux-arch, msalter, sparclinux, xen-devel,
	linux, linux-sh, will.deacon, korea.drzix, x86,
	anil.s.keshavamurthy, fontana, mingo, linux-arm-kernel,
	catalin.marinas, dvhart, dwmw2, david.vrabel, pali.rohar,
	keescook, arnd, realmz6, a-jacquiot, linux, rusty, rostedt,
	chris

On Tue, Aug 09, 2016 at 09:09:07AM -0700, James Bottomley wrote:
> On Tue, 2016-08-09 at 15:24 +0100, One Thousand Gnomes wrote:
> > > table development go under copyleft-next, Rusty recently asked for 
> > > code to go in prior to the license tag being added denoting this 
> > > license as GPL-compatible [3] -- I had noted in the patch 
> > > submission which annotated copyleft-next's compatibility to GPLv2 
> > > that copyleft-next is the license of choice for ongoing kernel 
> > > development on my end [4]. If this is objectionable I'm happy to 
> > > change it to GPLv2 however I'd like a reason provided as I've gone 
> > > through all possible channels to ensure this is kosher, including
> > > vetting by 3 attorneys now, 2 at SUSE.
> > 
> > You don't need a new tag, you can use "GPL" or "GPL and additional
> > rights". In fact you don't want any other tag because when combined
> >  with the kernel it is GPLv2 anyway because the only way the two are 
> > fully compatible is for the kernel community to license the derived 
> > work under the GPL.
> 
> This is the module tag ... it says what licence the module is under,
> not the licence for the module combined with the kernel, which is
> always GPLv2 because the stricter licence rules.

As per Linus' recommendations [0] if I add a module I'll be using
MODULE_LICENSE("GPL") if using copyleft-next. Either way this series
didn't add a module yet so no need for that yet, but it does use
copyleft-next in headers / C code.

[0] https://lkml.kernel.org/r/CA+55aFyhxcvD+q7tp+-yrSFDKfR0mOHgyEAe=f_94aKLsOu0Og@mail.gmail.com

> However, if I
> want my binary only modules to be combined with Linux, I have to follow
> GPLv2 compliance because GPLv2 becomes the ruling licence of the
> combination.  The same would apply to this copyleft-next, even after 15
> years.

And this what really matters here.

> The US copyright office defines a copyright work as anything which is
> "an original work of authorship fixed in any tangible medium of
> expression".  That means any change to an existing work (i.e. by a
> patch) which contains enough originality to make the changed work
> distinct from the old work is ipso facto a new work.  under copyright
> -next this new work has a sunset 15 years from its creation by
> combination, not 15 years from the original.  This means a constantly
> updated work never sunsets.  Sure, you can go back 15 years and claim
> the code at that time has passed into the public domain but you can't
> do that if you also want the benefit of later changes.

Agreed.

  Luis

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-08-10 17:03       ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-10 17:03 UTC (permalink / raw)
  To: James Bottomley
  Cc: One Thousand Gnomes, Luis R. Rodriguez, hpa, tglx, mingo, bp,
	linux, mhiramat, masami.hiramatsu.pt, jbaron, heiko.carstens,
	ananth, anil.s.keshavamurthy, davem, realmz6, x86, luto,
	keescook, torvalds, gregkh, rusty, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker, xen-devel, ak,
	pali.rohar, dvhart, platform-driver-x86, mmarek, linux, jkosina,
	korea.drzix, linux-kbuild, tony.luck, akpm, linux-ia64,
	linux-arm-kernel, linux-sh, sparclinux, catalin.marinas,
	will.deacon, rostedt, jpoimboe, msalter, a-jacquiot

On Tue, Aug 09, 2016 at 09:09:07AM -0700, James Bottomley wrote:
> On Tue, 2016-08-09 at 15:24 +0100, One Thousand Gnomes wrote:
> > > table development go under copyleft-next, Rusty recently asked for 
> > > code to go in prior to the license tag being added denoting this 
> > > license as GPL-compatible [3] -- I had noted in the patch 
> > > submission which annotated copyleft-next's compatibility to GPLv2 
> > > that copyleft-next is the license of choice for ongoing kernel 
> > > development on my end [4]. If this is objectionable I'm happy to 
> > > change it to GPLv2 however I'd like a reason provided as I've gone 
> > > through all possible channels to ensure this is kosher, including
> > > vetting by 3 attorneys now, 2 at SUSE.
> > 
> > You don't need a new tag, you can use "GPL" or "GPL and additional
> > rights". In fact you don't want any other tag because when combined
> >  with the kernel it is GPLv2 anyway because the only way the two are 
> > fully compatible is for the kernel community to license the derived 
> > work under the GPL.
> 
> This is the module tag ... it says what licence the module is under,
> not the licence for the module combined with the kernel, which is
> always GPLv2 because the stricter licence rules.

As per Linus' recommendations [0] if I add a module I'll be using
MODULE_LICENSE("GPL") if using copyleft-next. Either way this series
didn't add a module yet so no need for that yet, but it does use
copyleft-next in headers / C code.

[0] https://lkml.kernel.org/r/CA+55aFyhxcvD+q7tp+-yrSFDKfR0mOHgyEAe=f_94aKLsOu0Og@mail.gmail.com

> However, if I
> want my binary only modules to be combined with Linux, I have to follow
> GPLv2 compliance because GPLv2 becomes the ruling licence of the
> combination.  The same would apply to this copyleft-next, even after 15
> years.

And this what really matters here.

> The US copyright office defines a copyright work as anything which is
> "an original work of authorship fixed in any tangible medium of
> expression".  That means any change to an existing work (i.e. by a
> patch) which contains enough originality to make the changed work
> distinct from the old work is ipso facto a new work.  under copyright
> -next this new work has a sunset 15 years from its creation by
> combination, not 15 years from the original.  This means a constantly
> updated work never sunsets.  Sure, you can go back 15 years and claim
> the code at that time has passed into the public domain but you can't
> do that if you also want the benefit of later changes.

Agreed.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-08-09  3:55         ` Borislav Petkov
  (?)
@ 2016-08-12  3:51           ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-12  3:51 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko

On Tue, Aug 09, 2016 at 05:55:08AM +0200, Borislav Petkov wrote:
> On Mon, Aug 08, 2016 at 05:05:39PM +0200, Luis R. Rodriguez wrote:
> > > So how can I disable those table-* things from even getting built? Avoid
> > > using table-y? But then everything declared table-y will be built
> > > unconditionally. I don't think I like that. :-\
> > 
> > I suppose we could make this configurable... But frankly I would prefer to
> > instead just document that this use should be carefully considered instead,
> > and let this be up to the maintainers. We can make it easily configurable so
> > we can do that later becomes a required, I don't think its needed though
> > given maintainers should use it only when needed.
> 
> You know how maintainers are just people, right? At least in most cases :-)
> 
> I think it would be better if it were machine-enforceable somehow.
> Maybe allow it only for core code and have a single, per-arch file
> arch/x86/linker_tables or so where all those statements are collected
> and can be eyeballed by more people. Dunno, just trying to think of
> something here...

OK I've added CONFIG_BUILD_AVOID_BITROT.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12  3:51           ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-12  3:51 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko

On Tue, Aug 09, 2016 at 05:55:08AM +0200, Borislav Petkov wrote:
> On Mon, Aug 08, 2016 at 05:05:39PM +0200, Luis R. Rodriguez wrote:
> > > So how can I disable those table-* things from even getting built? Avoid
> > > using table-y? But then everything declared table-y will be built
> > > unconditionally. I don't think I like that. :-\
> > 
> > I suppose we could make this configurable... But frankly I would prefer to
> > instead just document that this use should be carefully considered instead,
> > and let this be up to the maintainers. We can make it easily configurable so
> > we can do that later becomes a required, I don't think its needed though
> > given maintainers should use it only when needed.
> 
> You know how maintainers are just people, right? At least in most cases :-)
> 
> I think it would be better if it were machine-enforceable somehow.
> Maybe allow it only for core code and have a single, per-arch file
> arch/x86/linker_tables or so where all those statements are collected
> and can be eyeballed by more people. Dunno, just trying to think of
> something here...

OK I've added CONFIG_BUILD_AVOID_BITROT.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12  3:51           ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-12  3:51 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker, xen-devel, ak,
	pali.rohar, dvhart, platform-driver-x86, mmarek, linux, jkosina,
	korea.drzix, linux-kbuild, tony.luck, akpm, linux-ia64,
	linux-arm-kernel, linux-sh, sparclinux, catalin.marinas,
	will.deacon, rostedt, jpoimboe

On Tue, Aug 09, 2016 at 05:55:08AM +0200, Borislav Petkov wrote:
> On Mon, Aug 08, 2016 at 05:05:39PM +0200, Luis R. Rodriguez wrote:
> > > So how can I disable those table-* things from even getting built? Avoid
> > > using table-y? But then everything declared table-y will be built
> > > unconditionally. I don't think I like that. :-\
> > 
> > I suppose we could make this configurable... But frankly I would prefer to
> > instead just document that this use should be carefully considered instead,
> > and let this be up to the maintainers. We can make it easily configurable so
> > we can do that later becomes a required, I don't think its needed though
> > given maintainers should use it only when needed.
> 
> You know how maintainers are just people, right? At least in most cases :-)
> 
> I think it would be better if it were machine-enforceable somehow.
> Maybe allow it only for core code and have a single, per-arch file
> arch/x86/linker_tables or so where all those statements are collected
> and can be eyeballed by more people. Dunno, just trying to think of
> something here...

OK I've added CONFIG_BUILD_AVOID_BITROT.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-08-12  3:51           ` Luis R. Rodriguez
  (?)
@ 2016-08-12  5:23             ` Borislav Petkov
  -1 siblings, 0 replies; 176+ messages in thread
From: Borislav Petkov @ 2016-08-12  5:23 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, linux, mhiramat, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-

On Fri, Aug 12, 2016 at 05:51:29AM +0200, Luis R. Rodriguez wrote:
> OK I've added CONFIG_BUILD_AVOID_BITROT.

What does that do?

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12  5:23             ` Borislav Petkov
  0 siblings, 0 replies; 176+ messages in thread
From: Borislav Petkov @ 2016-08-12  5:23 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, linux, mhiramat, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-

On Fri, Aug 12, 2016 at 05:51:29AM +0200, Luis R. Rodriguez wrote:
> OK I've added CONFIG_BUILD_AVOID_BITROT.

What does that do?

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12  5:23             ` Borislav Petkov
  0 siblings, 0 replies; 176+ messages in thread
From: Borislav Petkov @ 2016-08-12  5:23 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, linux, mhiramat, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe

On Fri, Aug 12, 2016 at 05:51:29AM +0200, Luis R. Rodriguez wrote:
> OK I've added CONFIG_BUILD_AVOID_BITROT.

What does that do?

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-08-12  5:23             ` Borislav Petkov
  (?)
@ 2016-08-12  6:50               ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-12  6:50 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko

On Fri, Aug 12, 2016 at 07:23:03AM +0200, Borislav Petkov wrote:
> On Fri, Aug 12, 2016 at 05:51:29AM +0200, Luis R. Rodriguez wrote:
> > OK I've added CONFIG_BUILD_AVOID_BITROT.
> 
> What does that do?


Enabling it allows the forced compilation chosen by maintainers.
Otherwise forced compilations with the new special targets are
ignored. I've gone with table-obj-y and table-lib-y as we have
to support both lib-y and obj-y respective targets.

diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 33e2966dd741..7893e3b8da82 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1895,6 +1895,30 @@ config PROVIDE_OHCI1394_DMA_INIT
 
 	  See Documentation/debugging-via-ohci1394.txt for more information.
 
+config BUILD_AVOID_BITROT
+	bool "Always force building specially annotated"
+	default y
+	help
+	  If enabled then the the special table-* Makefile targets will always
+	  be forced to be compiled even if their respective CONFIG_ option has
+	  been disabled, but its objects will only be linked in if the same
+	  respective CONFIG_ option has been enabled. This helps avoid code
+	  bit rot issues, use for these targets should be carefully considred
+	  by maintainers. You can safely enable this option at the expense of
+	  increasing compile time slightly. Enabling this option helps avoid
+	  code bit rot by taking advantage of the facilities provided and
+	  enabled by using linker tables documented under:
+
+	  include/linux/tables.h
+
+	  The special targets supported are:
+
+	    o table-obj-y
+	    o table-lib-y
+
+	  Say Y unless you are a grumpy maintainer and don't trust other
+	  maintainer's judgements on what code should always get compiled.
+
 config BUILD_DOCSRC
 	bool "Build targets in Documentation/ tree"
 	depends on HEADERS_CHECK
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 002857fe8d0d..17ced5ac44b2 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -91,7 +91,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) $(table-y)) \
+__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y) \
+				$(table-obj-y)) \
 	 $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \
 	 $(subdir-ym) $(always)
 	@:
@@ -325,8 +326,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) $(table-y) $(MAKECMDGOALS) $(always)
+targets += $(real-objs-y) $(real-objs-m) $(lib-y) $(table-lib-y)
+targets += $(extra-y) $(table-obj-y) $(MAKECMDGOALS) $(always)
 
 # Linker scripts preprocessor (.lds.S -> .lds)
 # ---------------------------------------------------------------------------
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 494f215ebaa4..58db6b503aca 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -12,15 +12,14 @@ export KBUILD_SUBDIR_CCFLAGS := $(KBUILD_SUBDIR_CCFLAGS) $(subdir-ccflags-y)
 # Figure out what we need to build from the various variables
 # ===================================== 
-# Linker tables objects always wish to be built to avoid bit-rot in
-# code, but only linked in *iff* they were enabled. We accomplish this
-# using pegging linker table objects into extra-y, which forces
-# compilation and then using the respective table-y and table-m as
-# as hints for things we do want enabled. Objects which we want to
-# avoid linking in will be in table-, not table-y and table-m.
-extra-y += $(table-)
-obj-m += $(table-m)
-obj-y += $(table-y)
+ifeq ($(CONFIG_BUILD_AVOID_BITROT),y)
+extra-y += $(table-obj-) $(table-lib-)
+endif
+
+obj-m += $(table-obj-m)
+obj-y += $(table-obj-y)
+lib-m += $(table-lib-m)
+lib-y += $(table-lib-y)
 
 # When an object is listed to be built compiled-in and modular,
 # only build the compiled-in version
@@ -82,8 +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))
-table-y		:= $(addprefix $(obj)/,$(table-y))
-table-m		:= $(addprefix $(obj)/,$(table-m))
+table-obj-y		:= $(addprefix $(obj)/,$(table-obj-y))
+table-obj-m		:= $(addprefix $(obj)/,$(table-obj-m))
 always		:= $(addprefix $(obj)/,$(always))
 targets		:= $(addprefix $(obj)/,$(targets))
 modorder	:= $(addprefix $(obj)/,$(modorder))

^ permalink raw reply related	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12  6:50               ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-12  6:50 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko

On Fri, Aug 12, 2016 at 07:23:03AM +0200, Borislav Petkov wrote:
> On Fri, Aug 12, 2016 at 05:51:29AM +0200, Luis R. Rodriguez wrote:
> > OK I've added CONFIG_BUILD_AVOID_BITROT.
> 
> What does that do?


Enabling it allows the forced compilation chosen by maintainers.
Otherwise forced compilations with the new special targets are
ignored. I've gone with table-obj-y and table-lib-y as we have
to support both lib-y and obj-y respective targets.

diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 33e2966dd741..7893e3b8da82 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1895,6 +1895,30 @@ config PROVIDE_OHCI1394_DMA_INIT
 
 	  See Documentation/debugging-via-ohci1394.txt for more information.
 
+config BUILD_AVOID_BITROT
+	bool "Always force building specially annotated"
+	default y
+	help
+	  If enabled then the the special table-* Makefile targets will always
+	  be forced to be compiled even if their respective CONFIG_ option has
+	  been disabled, but its objects will only be linked in if the same
+	  respective CONFIG_ option has been enabled. This helps avoid code
+	  bit rot issues, use for these targets should be carefully considred
+	  by maintainers. You can safely enable this option at the expense of
+	  increasing compile time slightly. Enabling this option helps avoid
+	  code bit rot by taking advantage of the facilities provided and
+	  enabled by using linker tables documented under:
+
+	  include/linux/tables.h
+
+	  The special targets supported are:
+
+	    o table-obj-y
+	    o table-lib-y
+
+	  Say Y unless you are a grumpy maintainer and don't trust other
+	  maintainer's judgements on what code should always get compiled.
+
 config BUILD_DOCSRC
 	bool "Build targets in Documentation/ tree"
 	depends on HEADERS_CHECK
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 002857fe8d0d..17ced5ac44b2 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -91,7 +91,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) $(table-y)) \
+__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y) \
+				$(table-obj-y)) \
 	 $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \
 	 $(subdir-ym) $(always)
 	@:
@@ -325,8 +326,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) $(table-y) $(MAKECMDGOALS) $(always)
+targets += $(real-objs-y) $(real-objs-m) $(lib-y) $(table-lib-y)
+targets += $(extra-y) $(table-obj-y) $(MAKECMDGOALS) $(always)
 
 # Linker scripts preprocessor (.lds.S -> .lds)
 # ---------------------------------------------------------------------------
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 494f215ebaa4..58db6b503aca 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -12,15 +12,14 @@ export KBUILD_SUBDIR_CCFLAGS := $(KBUILD_SUBDIR_CCFLAGS) $(subdir-ccflags-y)
 # Figure out what we need to build from the various variables
 # ===========================================================================
 
-# Linker tables objects always wish to be built to avoid bit-rot in
-# code, but only linked in *iff* they were enabled. We accomplish this
-# using pegging linker table objects into extra-y, which forces
-# compilation and then using the respective table-y and table-m as
-# as hints for things we do want enabled. Objects which we want to
-# avoid linking in will be in table-, not table-y and table-m.
-extra-y += $(table-)
-obj-m += $(table-m)
-obj-y += $(table-y)
+ifeq ($(CONFIG_BUILD_AVOID_BITROT),y)
+extra-y += $(table-obj-) $(table-lib-)
+endif
+
+obj-m += $(table-obj-m)
+obj-y += $(table-obj-y)
+lib-m += $(table-lib-m)
+lib-y += $(table-lib-y)
 
 # When an object is listed to be built compiled-in and modular,
 # only build the compiled-in version
@@ -82,8 +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))
-table-y		:= $(addprefix $(obj)/,$(table-y))
-table-m		:= $(addprefix $(obj)/,$(table-m))
+table-obj-y		:= $(addprefix $(obj)/,$(table-obj-y))
+table-obj-m		:= $(addprefix $(obj)/,$(table-obj-m))
 always		:= $(addprefix $(obj)/,$(always))
 targets		:= $(addprefix $(obj)/,$(targets))
 modorder	:= $(addprefix $(obj)/,$(modorder))

^ permalink raw reply related	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12  6:50               ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-12  6:50 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker, xen-devel, ak,
	pali.rohar, dvhart, platform-driver-x86, mmarek, linux, jkosina,
	korea.drzix, linux-kbuild, tony.luck, akpm, linux-ia64,
	linux-arm-kernel, linux-sh, sparclinux, catalin.marinas,
	will.deacon, rostedt, jpoimboe

On Fri, Aug 12, 2016 at 07:23:03AM +0200, Borislav Petkov wrote:
> On Fri, Aug 12, 2016 at 05:51:29AM +0200, Luis R. Rodriguez wrote:
> > OK I've added CONFIG_BUILD_AVOID_BITROT.
> 
> What does that do?


Enabling it allows the forced compilation chosen by maintainers.
Otherwise forced compilations with the new special targets are
ignored. I've gone with table-obj-y and table-lib-y as we have
to support both lib-y and obj-y respective targets.

diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
index 33e2966dd741..7893e3b8da82 100644
--- a/lib/Kconfig.debug
+++ b/lib/Kconfig.debug
@@ -1895,6 +1895,30 @@ config PROVIDE_OHCI1394_DMA_INIT
 
 	  See Documentation/debugging-via-ohci1394.txt for more information.
 
+config BUILD_AVOID_BITROT
+	bool "Always force building specially annotated"
+	default y
+	help
+	  If enabled then the the special table-* Makefile targets will always
+	  be forced to be compiled even if their respective CONFIG_ option has
+	  been disabled, but its objects will only be linked in if the same
+	  respective CONFIG_ option has been enabled. This helps avoid code
+	  bit rot issues, use for these targets should be carefully considred
+	  by maintainers. You can safely enable this option at the expense of
+	  increasing compile time slightly. Enabling this option helps avoid
+	  code bit rot by taking advantage of the facilities provided and
+	  enabled by using linker tables documented under:
+
+	  include/linux/tables.h
+
+	  The special targets supported are:
+
+	    o table-obj-y
+	    o table-lib-y
+
+	  Say Y unless you are a grumpy maintainer and don't trust other
+	  maintainer's judgements on what code should always get compiled.
+
 config BUILD_DOCSRC
 	bool "Build targets in Documentation/ tree"
 	depends on HEADERS_CHECK
diff --git a/scripts/Makefile.build b/scripts/Makefile.build
index 002857fe8d0d..17ced5ac44b2 100644
--- a/scripts/Makefile.build
+++ b/scripts/Makefile.build
@@ -91,7 +91,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) $(table-y)) \
+__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y) \
+				$(table-obj-y)) \
 	 $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \
 	 $(subdir-ym) $(always)
 	@:
@@ -325,8 +326,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) $(table-y) $(MAKECMDGOALS) $(always)
+targets += $(real-objs-y) $(real-objs-m) $(lib-y) $(table-lib-y)
+targets += $(extra-y) $(table-obj-y) $(MAKECMDGOALS) $(always)
 
 # Linker scripts preprocessor (.lds.S -> .lds)
 # ---------------------------------------------------------------------------
diff --git a/scripts/Makefile.lib b/scripts/Makefile.lib
index 494f215ebaa4..58db6b503aca 100644
--- a/scripts/Makefile.lib
+++ b/scripts/Makefile.lib
@@ -12,15 +12,14 @@ export KBUILD_SUBDIR_CCFLAGS := $(KBUILD_SUBDIR_CCFLAGS) $(subdir-ccflags-y)
 # Figure out what we need to build from the various variables
 # ===========================================================================
 
-# Linker tables objects always wish to be built to avoid bit-rot in
-# code, but only linked in *iff* they were enabled. We accomplish this
-# using pegging linker table objects into extra-y, which forces
-# compilation and then using the respective table-y and table-m as
-# as hints for things we do want enabled. Objects which we want to
-# avoid linking in will be in table-, not table-y and table-m.
-extra-y += $(table-)
-obj-m += $(table-m)
-obj-y += $(table-y)
+ifeq ($(CONFIG_BUILD_AVOID_BITROT),y)
+extra-y += $(table-obj-) $(table-lib-)
+endif
+
+obj-m += $(table-obj-m)
+obj-y += $(table-obj-y)
+lib-m += $(table-lib-m)
+lib-y += $(table-lib-y)
 
 # When an object is listed to be built compiled-in and modular,
 # only build the compiled-in version
@@ -82,8 +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))
-table-y		:= $(addprefix $(obj)/,$(table-y))
-table-m		:= $(addprefix $(obj)/,$(table-m))
+table-obj-y		:= $(addprefix $(obj)/,$(table-obj-y))
+table-obj-m		:= $(addprefix $(obj)/,$(table-obj-m))
 always		:= $(addprefix $(obj)/,$(always))
 targets		:= $(addprefix $(obj)/,$(targets))
 modorder	:= $(addprefix $(obj)/,$(modorder))

^ permalink raw reply related	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-08-12  6:50               ` Luis R. Rodriguez
  (?)
@ 2016-08-12  7:25                 ` Borislav Petkov
  -1 siblings, 0 replies; 176+ messages in thread
From: Borislav Petkov @ 2016-08-12  7:25 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, linux, mhiramat, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-

On Fri, Aug 12, 2016 at 08:50:11AM +0200, Luis R. Rodriguez wrote:
> On Fri, Aug 12, 2016 at 07:23:03AM +0200, Borislav Petkov wrote:
> > On Fri, Aug 12, 2016 at 05:51:29AM +0200, Luis R. Rodriguez wrote:
> > > OK I've added CONFIG_BUILD_AVOID_BITROT.
> > 
> > What does that do?
> 
> 
> Enabling it allows the forced compilation chosen by maintainers.
> Otherwise forced compilations with the new special targets are
> ignored.

Nice.

> I've gone with table-obj-y and table-lib-y as we have
> to support both lib-y and obj-y respective targets.
> 
> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> index 33e2966dd741..7893e3b8da82 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -1895,6 +1895,30 @@ config PROVIDE_OHCI1394_DMA_INIT
>  
>  	  See Documentation/debugging-via-ohci1394.txt for more information.
>  
> +config BUILD_AVOID_BITROT
> +	bool "Always force building specially annotated"

					   ...annotated targets"

> +	default y
> +	help
> +	  If enabled then the the special table-* Makefile targets will always
> +	  be forced to be compiled even if their respective CONFIG_ option has
> +	  been disabled, but its objects will only be linked in if the same
> +	  respective CONFIG_ option has been enabled. This helps avoid code
> +	  bit rot issues, use for these targets should be carefully considred
> +	  by maintainers. You can safely enable this option at the expense of
> +	  increasing compile time slightly. Enabling this option helps avoid

s/slightly//

:-)

> +	  code bit rot by taking advantage of the facilities provided and
> +	  enabled by using linker tables documented under:
> +
> +	  include/linux/tables.h
> +
> +	  The special targets supported are:
> +
> +	    o table-obj-y
> +	    o table-lib-y
> +
> +	  Say Y unless you are a grumpy maintainer and don't trust other
> +	  maintainer's judgements on what code should always get compiled.

... or you're running a tiny-config setup
... or you're an embedded, resource-constrained person
... or you simply don't want to have stuff which is forcibly enabled on you even
if you're never going to need it
...

I got a million o'those :-)

Thanks.

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12  7:25                 ` Borislav Petkov
  0 siblings, 0 replies; 176+ messages in thread
From: Borislav Petkov @ 2016-08-12  7:25 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, linux, mhiramat, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-

On Fri, Aug 12, 2016 at 08:50:11AM +0200, Luis R. Rodriguez wrote:
> On Fri, Aug 12, 2016 at 07:23:03AM +0200, Borislav Petkov wrote:
> > On Fri, Aug 12, 2016 at 05:51:29AM +0200, Luis R. Rodriguez wrote:
> > > OK I've added CONFIG_BUILD_AVOID_BITROT.
> > 
> > What does that do?
> 
> 
> Enabling it allows the forced compilation chosen by maintainers.
> Otherwise forced compilations with the new special targets are
> ignored.

Nice.

> I've gone with table-obj-y and table-lib-y as we have
> to support both lib-y and obj-y respective targets.
> 
> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> index 33e2966dd741..7893e3b8da82 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -1895,6 +1895,30 @@ config PROVIDE_OHCI1394_DMA_INIT
>  
>  	  See Documentation/debugging-via-ohci1394.txt for more information.
>  
> +config BUILD_AVOID_BITROT
> +	bool "Always force building specially annotated"

					   ...annotated targets"

> +	default y
> +	help
> +	  If enabled then the the special table-* Makefile targets will always
> +	  be forced to be compiled even if their respective CONFIG_ option has
> +	  been disabled, but its objects will only be linked in if the same
> +	  respective CONFIG_ option has been enabled. This helps avoid code
> +	  bit rot issues, use for these targets should be carefully considred
> +	  by maintainers. You can safely enable this option at the expense of
> +	  increasing compile time slightly. Enabling this option helps avoid

s/slightly//

:-)

> +	  code bit rot by taking advantage of the facilities provided and
> +	  enabled by using linker tables documented under:
> +
> +	  include/linux/tables.h
> +
> +	  The special targets supported are:
> +
> +	    o table-obj-y
> +	    o table-lib-y
> +
> +	  Say Y unless you are a grumpy maintainer and don't trust other
> +	  maintainer's judgements on what code should always get compiled.

... or you're running a tiny-config setup
... or you're an embedded, resource-constrained person
... or you simply don't want to have stuff which is forcibly enabled on you even
if you're never going to need it
...

I got a million o'those :-)

Thanks.

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12  7:25                 ` Borislav Petkov
  0 siblings, 0 replies; 176+ messages in thread
From: Borislav Petkov @ 2016-08-12  7:25 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, linux, mhiramat, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe

On Fri, Aug 12, 2016 at 08:50:11AM +0200, Luis R. Rodriguez wrote:
> On Fri, Aug 12, 2016 at 07:23:03AM +0200, Borislav Petkov wrote:
> > On Fri, Aug 12, 2016 at 05:51:29AM +0200, Luis R. Rodriguez wrote:
> > > OK I've added CONFIG_BUILD_AVOID_BITROT.
> > 
> > What does that do?
> 
> 
> Enabling it allows the forced compilation chosen by maintainers.
> Otherwise forced compilations with the new special targets are
> ignored.

Nice.

> I've gone with table-obj-y and table-lib-y as we have
> to support both lib-y and obj-y respective targets.
> 
> diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> index 33e2966dd741..7893e3b8da82 100644
> --- a/lib/Kconfig.debug
> +++ b/lib/Kconfig.debug
> @@ -1895,6 +1895,30 @@ config PROVIDE_OHCI1394_DMA_INIT
>  
>  	  See Documentation/debugging-via-ohci1394.txt for more information.
>  
> +config BUILD_AVOID_BITROT
> +	bool "Always force building specially annotated"

					   ...annotated targets"

> +	default y
> +	help
> +	  If enabled then the the special table-* Makefile targets will always
> +	  be forced to be compiled even if their respective CONFIG_ option has
> +	  been disabled, but its objects will only be linked in if the same
> +	  respective CONFIG_ option has been enabled. This helps avoid code
> +	  bit rot issues, use for these targets should be carefully considred
> +	  by maintainers. You can safely enable this option at the expense of
> +	  increasing compile time slightly. Enabling this option helps avoid

s/slightly//

:-)

> +	  code bit rot by taking advantage of the facilities provided and
> +	  enabled by using linker tables documented under:
> +
> +	  include/linux/tables.h
> +
> +	  The special targets supported are:
> +
> +	    o table-obj-y
> +	    o table-lib-y
> +
> +	  Say Y unless you are a grumpy maintainer and don't trust other
> +	  maintainer's judgements on what code should always get compiled.

... or you're running a tiny-config setup
... or you're an embedded, resource-constrained person
... or you simply don't want to have stuff which is forcibly enabled on you even
if you're never going to need it
...

I got a million o'those :-)

Thanks.

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-08-12  7:25                 ` Borislav Petkov
  (?)
@ 2016-08-12 15:28                   ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-12 15:28 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: gnomes, linux-ia64, jkosina, benh, ming.lei, heiko.carstens,
	platform-driver-x86, paul.gortmaker, hpa, masami.hiramatsu.pt,
	linux-arch, sparclinux, xen-devel, linux, linux-sh, will.deacon,
	korea.drzix, x86, anil.s.keshavamurthy, fontana, torvalds, mingo,
	linux-arm-kernel, catalin.marinas, dvhart, david.vrabel,
	pali.rohar, keescook, arnd, realmz6, linux, rusty, rostedt,
	christopher.denicolo, jbaron

On Fri, Aug 12, 2016 at 09:25:07AM +0200, Borislav Petkov wrote:
> On Fri, Aug 12, 2016 at 08:50:11AM +0200, Luis R. Rodriguez wrote:
> > On Fri, Aug 12, 2016 at 07:23:03AM +0200, Borislav Petkov wrote:
> > > On Fri, Aug 12, 2016 at 05:51:29AM +0200, Luis R. Rodriguez wrote:
> > > > OK I've added CONFIG_BUILD_AVOID_BITROT.
> > > 
> > > What does that do?
> > 
> > 
> > Enabling it allows the forced compilation chosen by maintainers.
> > Otherwise forced compilations with the new special targets are
> > ignored.
> 
> Nice.
> 
> > I've gone with table-obj-y and table-lib-y as we have
> > to support both lib-y and obj-y respective targets.
> > 
> > diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> > index 33e2966dd741..7893e3b8da82 100644
> > --- a/lib/Kconfig.debug
> > +++ b/lib/Kconfig.debug
> > @@ -1895,6 +1895,30 @@ config PROVIDE_OHCI1394_DMA_INIT
> >  
> >  	  See Documentation/debugging-via-ohci1394.txt for more information.
> >  
> > +config BUILD_AVOID_BITROT
> > +	bool "Always force building specially annotated"
> 
> 					   ...annotated targets"
> 
> > +	default y
> > +	help
> > +	  If enabled then the the special table-* Makefile targets will always
> > +	  be forced to be compiled even if their respective CONFIG_ option has
> > +	  been disabled, but its objects will only be linked in if the same
> > +	  respective CONFIG_ option has been enabled. This helps avoid code
> > +	  bit rot issues, use for these targets should be carefully considred
> > +	  by maintainers. You can safely enable this option at the expense of
> > +	  increasing compile time slightly. Enabling this option helps avoid
> 
> s/slightly//
> 
> :-)
> 
> > +	  code bit rot by taking advantage of the facilities provided and
> > +	  enabled by using linker tables documented under:
> > +
> > +	  include/linux/tables.h
> > +
> > +	  The special targets supported are:
> > +
> > +	    o table-obj-y
> > +	    o table-lib-y
> > +
> > +	  Say Y unless you are a grumpy maintainer and don't trust other
> > +	  maintainer's judgements on what code should always get compiled.
> 
> ... or you're running a tiny-config setup

Even so, you don't link the compiled extra code so the only penalty
here is when compiling, nothing more. And if you are compiling typically
the cost here is just a few seconds.

> ... or you're an embedded, resource-constrained person

For the compilation of th kernel ?

> ... or you simply don't want to have stuff which is forcibly enabled on you even
> if you're never going to need it
> ...

Which seems to be the same as the reason I noted ?

> I got a million o'those :-)

I can remove the grumpy maintainer description :)

 Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12 15:28                   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-12 15:28 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: gnomes, linux-ia64, jkosina, benh, ming.lei, heiko.carstens,
	platform-driver-x86, paul.gortmaker, hpa, masami.hiramatsu.pt,
	linux-arch, sparclinux, xen-devel, linux, linux-sh, will.deacon,
	korea.drzix, x86, anil.s.keshavamurthy, fontana, torvalds, mingo,
	linux-arm-kernel, catalin.marinas, dvhart, david.vrabel,
	pali.rohar, keescook, arnd, realmz6, linux, rusty, rostedt,
	christopher.denicolo, jbaron, ananth

On Fri, Aug 12, 2016 at 09:25:07AM +0200, Borislav Petkov wrote:
> On Fri, Aug 12, 2016 at 08:50:11AM +0200, Luis R. Rodriguez wrote:
> > On Fri, Aug 12, 2016 at 07:23:03AM +0200, Borislav Petkov wrote:
> > > On Fri, Aug 12, 2016 at 05:51:29AM +0200, Luis R. Rodriguez wrote:
> > > > OK I've added CONFIG_BUILD_AVOID_BITROT.
> > > 
> > > What does that do?
> > 
> > 
> > Enabling it allows the forced compilation chosen by maintainers.
> > Otherwise forced compilations with the new special targets are
> > ignored.
> 
> Nice.
> 
> > I've gone with table-obj-y and table-lib-y as we have
> > to support both lib-y and obj-y respective targets.
> > 
> > diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> > index 33e2966dd741..7893e3b8da82 100644
> > --- a/lib/Kconfig.debug
> > +++ b/lib/Kconfig.debug
> > @@ -1895,6 +1895,30 @@ config PROVIDE_OHCI1394_DMA_INIT
> >  
> >  	  See Documentation/debugging-via-ohci1394.txt for more information.
> >  
> > +config BUILD_AVOID_BITROT
> > +	bool "Always force building specially annotated"
> 
> 					   ...annotated targets"
> 
> > +	default y
> > +	help
> > +	  If enabled then the the special table-* Makefile targets will always
> > +	  be forced to be compiled even if their respective CONFIG_ option has
> > +	  been disabled, but its objects will only be linked in if the same
> > +	  respective CONFIG_ option has been enabled. This helps avoid code
> > +	  bit rot issues, use for these targets should be carefully considred
> > +	  by maintainers. You can safely enable this option at the expense of
> > +	  increasing compile time slightly. Enabling this option helps avoid
> 
> s/slightly//
> 
> :-)
> 
> > +	  code bit rot by taking advantage of the facilities provided and
> > +	  enabled by using linker tables documented under:
> > +
> > +	  include/linux/tables.h
> > +
> > +	  The special targets supported are:
> > +
> > +	    o table-obj-y
> > +	    o table-lib-y
> > +
> > +	  Say Y unless you are a grumpy maintainer and don't trust other
> > +	  maintainer's judgements on what code should always get compiled.
> 
> ... or you're running a tiny-config setup

Even so, you don't link the compiled extra code so the only penalty
here is when compiling, nothing more. And if you are compiling typically
the cost here is just a few seconds.

> ... or you're an embedded, resource-constrained person

For the compilation of th kernel ?

> ... or you simply don't want to have stuff which is forcibly enabled on you even
> if you're never going to need it
> ...

Which seems to be the same as the reason I noted ?

> I got a million o'those :-)

I can remove the grumpy maintainer description :)

 Luis

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12 15:28                   ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-12 15:28 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker, xen-devel, ak,
	pali.rohar, dvhart, platform-driver-x86, mmarek, linux, jkosina,
	korea.drzix, linux-kbuild, tony.luck, akpm, linux-ia64,
	linux-arm-kernel, linux-sh, sparclinux, catalin.marinas,
	will.deacon, rostedt, jpoimboe

On Fri, Aug 12, 2016 at 09:25:07AM +0200, Borislav Petkov wrote:
> On Fri, Aug 12, 2016 at 08:50:11AM +0200, Luis R. Rodriguez wrote:
> > On Fri, Aug 12, 2016 at 07:23:03AM +0200, Borislav Petkov wrote:
> > > On Fri, Aug 12, 2016 at 05:51:29AM +0200, Luis R. Rodriguez wrote:
> > > > OK I've added CONFIG_BUILD_AVOID_BITROT.
> > > 
> > > What does that do?
> > 
> > 
> > Enabling it allows the forced compilation chosen by maintainers.
> > Otherwise forced compilations with the new special targets are
> > ignored.
> 
> Nice.
> 
> > I've gone with table-obj-y and table-lib-y as we have
> > to support both lib-y and obj-y respective targets.
> > 
> > diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
> > index 33e2966dd741..7893e3b8da82 100644
> > --- a/lib/Kconfig.debug
> > +++ b/lib/Kconfig.debug
> > @@ -1895,6 +1895,30 @@ config PROVIDE_OHCI1394_DMA_INIT
> >  
> >  	  See Documentation/debugging-via-ohci1394.txt for more information.
> >  
> > +config BUILD_AVOID_BITROT
> > +	bool "Always force building specially annotated"
> 
> 					   ...annotated targets"
> 
> > +	default y
> > +	help
> > +	  If enabled then the the special table-* Makefile targets will always
> > +	  be forced to be compiled even if their respective CONFIG_ option has
> > +	  been disabled, but its objects will only be linked in if the same
> > +	  respective CONFIG_ option has been enabled. This helps avoid code
> > +	  bit rot issues, use for these targets should be carefully considred
> > +	  by maintainers. You can safely enable this option at the expense of
> > +	  increasing compile time slightly. Enabling this option helps avoid
> 
> s/slightly//
> 
> :-)
> 
> > +	  code bit rot by taking advantage of the facilities provided and
> > +	  enabled by using linker tables documented under:
> > +
> > +	  include/linux/tables.h
> > +
> > +	  The special targets supported are:
> > +
> > +	    o table-obj-y
> > +	    o table-lib-y
> > +
> > +	  Say Y unless you are a grumpy maintainer and don't trust other
> > +	  maintainer's judgements on what code should always get compiled.
> 
> ... or you're running a tiny-config setup

Even so, you don't link the compiled extra code so the only penalty
here is when compiling, nothing more. And if you are compiling typically
the cost here is just a few seconds.

> ... or you're an embedded, resource-constrained person

For the compilation of th kernel ?

> ... or you simply don't want to have stuff which is forcibly enabled on you even
> if you're never going to need it
> ...

Which seems to be the same as the reason I noted ?

> I got a million o'those :-)

I can remove the grumpy maintainer description :)

 Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-08-12 15:28                   ` Luis R. Rodriguez
  (?)
@ 2016-08-12 15:51                     ` Borislav Petkov
  -1 siblings, 0 replies; 176+ messages in thread
From: Borislav Petkov @ 2016-08-12 15:51 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, linux, mhiramat, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-

On Fri, Aug 12, 2016 at 05:28:05PM +0200, Luis R. Rodriguez wrote:
> Even so, you don't link the compiled extra code so the only penalty
> here is when compiling, nothing more. And if you are compiling typically
> the cost here is just a few seconds.

Yeah, so let's make it clear that this is similar to COMPILE_TEST and
people with fast machines and who don't mind building a couple more
seconds longer, should enable it.

You don't want to be doing bit-rotting tests on small, weak machines,
which barely get done with the build as it is. I have a 32-bit atom
which takes hours to build a kernel. Enabling that there is not making
the kernel build any more fun.

> > ... or you simply don't want to have stuff which is forcibly enabled on you even
> > if you're never going to need it
> > ...
> 
> Which seems to be the same as the reason I noted ?

No, the reason is we don't force stuff down people's throats just
because we think we know better. Other people do that.

Instead, we help them make an informed decision by describing the
feature as precisely as possible.

> I can remove the grumpy maintainer description :)

Yap :-)

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12 15:51                     ` Borislav Petkov
  0 siblings, 0 replies; 176+ messages in thread
From: Borislav Petkov @ 2016-08-12 15:51 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, linux, mhiramat, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-

On Fri, Aug 12, 2016 at 05:28:05PM +0200, Luis R. Rodriguez wrote:
> Even so, you don't link the compiled extra code so the only penalty
> here is when compiling, nothing more. And if you are compiling typically
> the cost here is just a few seconds.

Yeah, so let's make it clear that this is similar to COMPILE_TEST and
people with fast machines and who don't mind building a couple more
seconds longer, should enable it.

You don't want to be doing bit-rotting tests on small, weak machines,
which barely get done with the build as it is. I have a 32-bit atom
which takes hours to build a kernel. Enabling that there is not making
the kernel build any more fun.

> > ... or you simply don't want to have stuff which is forcibly enabled on you even
> > if you're never going to need it
> > ...
> 
> Which seems to be the same as the reason I noted ?

No, the reason is we don't force stuff down people's throats just
because we think we know better. Other people do that.

Instead, we help them make an informed decision by describing the
feature as precisely as possible.

> I can remove the grumpy maintainer description :)

Yap :-)

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12 15:51                     ` Borislav Petkov
  0 siblings, 0 replies; 176+ messages in thread
From: Borislav Petkov @ 2016-08-12 15:51 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, linux, mhiramat, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe

On Fri, Aug 12, 2016 at 05:28:05PM +0200, Luis R. Rodriguez wrote:
> Even so, you don't link the compiled extra code so the only penalty
> here is when compiling, nothing more. And if you are compiling typically
> the cost here is just a few seconds.

Yeah, so let's make it clear that this is similar to COMPILE_TEST and
people with fast machines and who don't mind building a couple more
seconds longer, should enable it.

You don't want to be doing bit-rotting tests on small, weak machines,
which barely get done with the build as it is. I have a 32-bit atom
which takes hours to build a kernel. Enabling that there is not making
the kernel build any more fun.

> > ... or you simply don't want to have stuff which is forcibly enabled on you even
> > if you're never going to need it
> > ...
> 
> Which seems to be the same as the reason I noted ?

No, the reason is we don't force stuff down people's throats just
because we think we know better. Other people do that.

Instead, we help them make an informed decision by describing the
feature as precisely as possible.

> I can remove the grumpy maintainer description :)

Yap :-)

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-08-12 15:51                     ` Borislav Petkov
  (?)
@ 2016-08-12 17:04                       ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-12 17:04 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko

On Fri, Aug 12, 2016 at 05:51:21PM +0200, Borislav Petkov wrote:
> On Fri, Aug 12, 2016 at 05:28:05PM +0200, Luis R. Rodriguez wrote:
> > Even so, you don't link the compiled extra code so the only penalty
> > here is when compiling, nothing more. And if you are compiling typically
> > the cost here is just a few seconds.
> 
> Yeah, so let's make it clear that this is similar to COMPILE_TEST and
> people with fast machines and who don't mind building a couple more
> seconds longer, should enable it.

Sure, I'll also move it under COMPILE_TEST, and default it to n.

> You don't want to be doing bit-rotting tests on small, weak machines,
> which barely get done with the build as it is. I have a 32-bit atom
> which takes hours to build a kernel. Enabling that there is not making
> the kernel build any more fun.
> 
> > > ... or you simply don't want to have stuff which is forcibly enabled on you even
> > > if you're never going to need it
> > > ...
> > 
> > Which seems to be the same as the reason I noted ?
> 
> No, the reason is we don't force stuff down people's throats just
> because we think we know better. Other people do that.
> 
> Instead, we help them make an informed decision by describing the
> feature as precisely as possible.
> 
> > I can remove the grumpy maintainer description :)
> 
> Yap :-)

Alright, how's this new description:

diff --git a/init/Kconfig b/init/Kconfig
index cac3f096050d..73e4890c24c4 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -53,6 +53,34 @@ 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 "Always force building specially annotated targets"
+	default n
+	help
+	  If enabled then the the special table-* Makefile targets will always
+	  be forced to be compiled even if their respective CONFIG_ option has
+	  been disabled, but its objects will only be linked in if the same
+	  respective CONFIG_ option has been enabled. This helps avoid code
+	  bit rot issues, use for these targets should be carefully considred
+	  by maintainers. You can safely enable this option at the expense of
+	  increasing compile time. Enabling this option helps avoid code bit
+	  rot by taking advantage of the facilities provided and enabled by
+	  using linker tables documented under:
+
+	  include/linux/tables.h
+
+	  The special targets supported are:
+
+	    o table-obj-y
+	    o table-lib-y
+
+	  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

^ permalink raw reply related	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12 17:04                       ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-12 17:04 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko

On Fri, Aug 12, 2016 at 05:51:21PM +0200, Borislav Petkov wrote:
> On Fri, Aug 12, 2016 at 05:28:05PM +0200, Luis R. Rodriguez wrote:
> > Even so, you don't link the compiled extra code so the only penalty
> > here is when compiling, nothing more. And if you are compiling typically
> > the cost here is just a few seconds.
> 
> Yeah, so let's make it clear that this is similar to COMPILE_TEST and
> people with fast machines and who don't mind building a couple more
> seconds longer, should enable it.

Sure, I'll also move it under COMPILE_TEST, and default it to n.

> You don't want to be doing bit-rotting tests on small, weak machines,
> which barely get done with the build as it is. I have a 32-bit atom
> which takes hours to build a kernel. Enabling that there is not making
> the kernel build any more fun.
> 
> > > ... or you simply don't want to have stuff which is forcibly enabled on you even
> > > if you're never going to need it
> > > ...
> > 
> > Which seems to be the same as the reason I noted ?
> 
> No, the reason is we don't force stuff down people's throats just
> because we think we know better. Other people do that.
> 
> Instead, we help them make an informed decision by describing the
> feature as precisely as possible.
> 
> > I can remove the grumpy maintainer description :)
> 
> Yap :-)

Alright, how's this new description:

diff --git a/init/Kconfig b/init/Kconfig
index cac3f096050d..73e4890c24c4 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -53,6 +53,34 @@ 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 "Always force building specially annotated targets"
+	default n
+	help
+	  If enabled then the the special table-* Makefile targets will always
+	  be forced to be compiled even if their respective CONFIG_ option has
+	  been disabled, but its objects will only be linked in if the same
+	  respective CONFIG_ option has been enabled. This helps avoid code
+	  bit rot issues, use for these targets should be carefully considred
+	  by maintainers. You can safely enable this option at the expense of
+	  increasing compile time. Enabling this option helps avoid code bit
+	  rot by taking advantage of the facilities provided and enabled by
+	  using linker tables documented under:
+
+	  include/linux/tables.h
+
+	  The special targets supported are:
+
+	    o table-obj-y
+	    o table-lib-y
+
+	  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

^ permalink raw reply related	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12 17:04                       ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-12 17:04 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: Luis R. Rodriguez, hpa, tglx, mingo, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, gregkh, rusty, gnomes, alan, dwmw2, arnd, ming.lei,
	linux-arch, benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker, xen-devel, ak,
	pali.rohar, dvhart, platform-driver-x86, mmarek, linux, jkosina,
	korea.drzix, linux-kbuild, tony.luck, akpm, linux-ia64,
	linux-arm-kernel, linux-sh, sparclinux, catalin.marinas,
	will.deacon, rostedt, jpoimboe

On Fri, Aug 12, 2016 at 05:51:21PM +0200, Borislav Petkov wrote:
> On Fri, Aug 12, 2016 at 05:28:05PM +0200, Luis R. Rodriguez wrote:
> > Even so, you don't link the compiled extra code so the only penalty
> > here is when compiling, nothing more. And if you are compiling typically
> > the cost here is just a few seconds.
> 
> Yeah, so let's make it clear that this is similar to COMPILE_TEST and
> people with fast machines and who don't mind building a couple more
> seconds longer, should enable it.

Sure, I'll also move it under COMPILE_TEST, and default it to n.

> You don't want to be doing bit-rotting tests on small, weak machines,
> which barely get done with the build as it is. I have a 32-bit atom
> which takes hours to build a kernel. Enabling that there is not making
> the kernel build any more fun.
> 
> > > ... or you simply don't want to have stuff which is forcibly enabled on you even
> > > if you're never going to need it
> > > ...
> > 
> > Which seems to be the same as the reason I noted ?
> 
> No, the reason is we don't force stuff down people's throats just
> because we think we know better. Other people do that.
> 
> Instead, we help them make an informed decision by describing the
> feature as precisely as possible.
> 
> > I can remove the grumpy maintainer description :)
> 
> Yap :-)

Alright, how's this new description:

diff --git a/init/Kconfig b/init/Kconfig
index cac3f096050d..73e4890c24c4 100644
--- a/init/Kconfig
+++ b/init/Kconfig
@@ -53,6 +53,34 @@ 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 "Always force building specially annotated targets"
+	default n
+	help
+	  If enabled then the the special table-* Makefile targets will always
+	  be forced to be compiled even if their respective CONFIG_ option has
+	  been disabled, but its objects will only be linked in if the same
+	  respective CONFIG_ option has been enabled. This helps avoid code
+	  bit rot issues, use for these targets should be carefully considred
+	  by maintainers. You can safely enable this option at the expense of
+	  increasing compile time. Enabling this option helps avoid code bit
+	  rot by taking advantage of the facilities provided and enabled by
+	  using linker tables documented under:
+
+	  include/linux/tables.h
+
+	  The special targets supported are:
+
+	    o table-obj-y
+	    o table-lib-y
+
+	  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

^ permalink raw reply related	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-08-12 17:04                       ` Luis R. Rodriguez
  (?)
@ 2016-08-12 17:35                         ` Borislav Petkov
  -1 siblings, 0 replies; 176+ messages in thread
From: Borislav Petkov @ 2016-08-12 17:35 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, linux, mhiramat, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-

On Fri, Aug 12, 2016 at 07:04:52PM +0200, Luis R. Rodriguez wrote:
> Alright, how's this new description:
> 
> diff --git a/init/Kconfig b/init/Kconfig
> index cac3f096050d..73e4890c24c4 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -53,6 +53,34 @@ 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 "Always force building specially annotated targets"
> +	default n
> +	help
> +	  If enabled then the the special table-* Makefile targets will always
> +	  be forced to be compiled even if their respective CONFIG_ option has

"will always be compiled" is already absolute.

> +	  been disabled, but its objects will only be linked in if the same
> +	  respective CONFIG_ option has been enabled. This helps avoid code
> +	  bit rot issues, use for these targets should be carefully considred

s/This helps avoid code bit rot issues, u/U/

The bit-rot thing comes again below.

> +	  by maintainers. You can safely enable this option at the expense of
> +	  increasing compile time. Enabling this option helps avoid code bit
> +	  rot by taking advantage of the facilities provided and enabled by
> +	  using linker tables documented under:
> +
> +	  include/linux/tables.h
> +
> +	  The special targets supported are:
> +
> +	    o table-obj-y
> +	    o table-lib-y
> +
> +	  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.
> +

Other than those minor formulation nits, yeah, nice!

Thanks.

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12 17:35                         ` Borislav Petkov
  0 siblings, 0 replies; 176+ messages in thread
From: Borislav Petkov @ 2016-08-12 17:35 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, linux, mhiramat, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-

On Fri, Aug 12, 2016 at 07:04:52PM +0200, Luis R. Rodriguez wrote:
> Alright, how's this new description:
> 
> diff --git a/init/Kconfig b/init/Kconfig
> index cac3f096050d..73e4890c24c4 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -53,6 +53,34 @@ 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 "Always force building specially annotated targets"
> +	default n
> +	help
> +	  If enabled then the the special table-* Makefile targets will always
> +	  be forced to be compiled even if their respective CONFIG_ option has

"will always be compiled" is already absolute.

> +	  been disabled, but its objects will only be linked in if the same
> +	  respective CONFIG_ option has been enabled. This helps avoid code
> +	  bit rot issues, use for these targets should be carefully considred

s/This helps avoid code bit rot issues, u/U/

The bit-rot thing comes again below.

> +	  by maintainers. You can safely enable this option at the expense of
> +	  increasing compile time. Enabling this option helps avoid code bit
> +	  rot by taking advantage of the facilities provided and enabled by
> +	  using linker tables documented under:
> +
> +	  include/linux/tables.h
> +
> +	  The special targets supported are:
> +
> +	    o table-obj-y
> +	    o table-lib-y
> +
> +	  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.
> +

Other than those minor formulation nits, yeah, nice!

Thanks.

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12 17:35                         ` Borislav Petkov
  0 siblings, 0 replies; 176+ messages in thread
From: Borislav Petkov @ 2016-08-12 17:35 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: hpa, tglx, mingo, linux, mhiramat, masami.hiramatsu.pt, jbaron,
	heiko.carstens, ananth, anil.s.keshavamurthy, davem, realmz6,
	x86, luto, keescook, torvalds, gregkh, rusty, gnomes, alan,
	dwmw2, arnd, ming.lei, linux-arch, benh, ananth, pebolle,
	fontana, ciaran.farrell, christopher.denicolo, david.vrabel,
	konrad.wilk, mcb30, jgross, andrew.cooper3, andriy.shevchenko,
	paul.gortmaker, xen-devel, ak, pali.rohar, dvhart,
	platform-driver-x86, mmarek, linux, jkosina, korea.drzix,
	linux-kbuild, tony.luck, akpm, linux-ia64, linux-arm-kernel,
	linux-sh, sparclinux, catalin.marinas, will.deacon, rostedt,
	jpoimboe

On Fri, Aug 12, 2016 at 07:04:52PM +0200, Luis R. Rodriguez wrote:
> Alright, how's this new description:
> 
> diff --git a/init/Kconfig b/init/Kconfig
> index cac3f096050d..73e4890c24c4 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -53,6 +53,34 @@ 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 "Always force building specially annotated targets"
> +	default n
> +	help
> +	  If enabled then the the special table-* Makefile targets will always
> +	  be forced to be compiled even if their respective CONFIG_ option has

"will always be compiled" is already absolute.

> +	  been disabled, but its objects will only be linked in if the same
> +	  respective CONFIG_ option has been enabled. This helps avoid code
> +	  bit rot issues, use for these targets should be carefully considred

s/This helps avoid code bit rot issues, u/U/

The bit-rot thing comes again below.

> +	  by maintainers. You can safely enable this option at the expense of
> +	  increasing compile time. Enabling this option helps avoid code bit
> +	  rot by taking advantage of the facilities provided and enabled by
> +	  using linker tables documented under:
> +
> +	  include/linux/tables.h
> +
> +	  The special targets supported are:
> +
> +	    o table-obj-y
> +	    o table-lib-y
> +
> +	  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.
> +

Other than those minor formulation nits, yeah, nice!

Thanks.

-- 
Regards/Gruss,
    Boris.

ECO tip #101: Trim your mails when you reply.
--

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-08-12 17:35                         ` Borislav Petkov
  (?)
  (?)
@ 2016-08-12 18:16                         ` Kees Cook
  -1 siblings, 0 replies; 176+ messages in thread
From: Kees Cook @ 2016-08-12 18:16 UTC (permalink / raw)
  To: Borislav Petkov
  Cc: gnomes, linux-ia64, Jiri Kosina, benh, Ming Lei, Heiko Carstens,
	platform-driver-x86, Paul Gortmaker, H. Peter Anvin,
	Masami Hiramatsu, linux-arch, sparclinux, xen-devel,
	Russell King - ARM Linux, linux-sh, Will Deacon, korea.drzix,
	x86, anil.s.keshavamurthy, fontana, Linus Torvalds, Ingo Molnar

Just some minor typos in descriptions I noticed below...

On Fri, Aug 12, 2016 at 10:35 AM, Borislav Petkov <bp@alien8.de> wrote:
> On Fri, Aug 12, 2016 at 07:04:52PM +0200, Luis R. Rodriguez wrote:
>> Alright, how's this new description:
>>
>> diff --git a/init/Kconfig b/init/Kconfig
>> index cac3f096050d..73e4890c24c4 100644
>> --- a/init/Kconfig
>> +++ b/init/Kconfig
>> @@ -53,6 +53,34 @@ 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 "Always force building specially annotated targets"
>> +     default n
>> +     help
>> +       If enabled then the the special table-* Makefile targets will always

"the the" -> "the"

>> +       be forced to be compiled even if their respective CONFIG_ option has
>
> "will always be compiled" is already absolute.
>
>> +       been disabled, but its objects will only be linked in if the same
>> +       respective CONFIG_ option has been enabled. This helps avoid code
>> +       bit rot issues, use for these targets should be carefully considred

"considered"

>
> s/This helps avoid code bit rot issues, u/U/
>
> The bit-rot thing comes again below.
>
>> +       by maintainers. You can safely enable this option at the expense of
>> +       increasing compile time. Enabling this option helps avoid code bit
>> +       rot by taking advantage of the facilities provided and enabled by
>> +       using linker tables documented under:
>> +
>> +       include/linux/tables.h
>> +
>> +       The special targets supported are:
>> +
>> +         o table-obj-y
>> +         o table-lib-y
>> +
>> +       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.
>> +
>
> Other than those minor formulation nits, yeah, nice!
>
> Thanks.
>
> --
> Regards/Gruss,
>     Boris.
>
> ECO tip #101: Trim your mails when you reply.
> --

-Kees

-- 
Kees Cook
Nexus Security

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-08-12 17:04                       ` Luis R. Rodriguez
  (?)
@ 2016-08-12 20:23                         ` Greg KH
  -1 siblings, 0 replies; 176+ messages in thread
From: Greg KH @ 2016-08-12 20:23 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Borislav Petkov, hpa, tglx, mingo, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, rusty, gnomes, alan, dwmw2, arnd, ming.lei, linux-arch,
	benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker

On Fri, Aug 12, 2016 at 07:04:52PM +0200, Luis R. Rodriguez wrote:
> Alright, how's this new description:
> 
> diff --git a/init/Kconfig b/init/Kconfig
> index cac3f096050d..73e4890c24c4 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -53,6 +53,34 @@ 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 "Always force building specially annotated targets"
> +	default n
> +	help
> +	  If enabled then the the special table-* Makefile targets will always
> +	  be forced to be compiled even if their respective CONFIG_ option has
> +	  been disabled, but its objects will only be linked in if the same
> +	  respective CONFIG_ option has been enabled. This helps avoid code
> +	  bit rot issues, use for these targets should be carefully considred
> +	  by maintainers. You can safely enable this option at the expense of
> +	  increasing compile time. Enabling this option helps avoid code bit
> +	  rot by taking advantage of the facilities provided and enabled by
> +	  using linker tables documented under:

As a kernel developer I have _no_ idea what this is trying to say at
all, sorry.

What is a "specially annotated target"?  Who is forcing it to be built?
What does it mean if it isn't built?

> +
> +	  include/linux/tables.h
> +
> +	  The special targets supported are:
> +
> +	    o table-obj-y
> +	    o table-lib-y

What does this mean to me as a developer?  What does it mean to a user
who wants to figure out if it should be enabled or not?

> +
> +	  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.

How does this test different subsystems?  How does disabling it not test
them?  Why would I care either way?

> +
> +	  Enabling this option never increases the size of your kernel.

Then what does it do?  Just burn electricity for no reason?

totally confused...

greg k-h

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12 20:23                         ` Greg KH
  0 siblings, 0 replies; 176+ messages in thread
From: Greg KH @ 2016-08-12 20:23 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Borislav Petkov, hpa, tglx, mingo, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, rusty, gnomes, alan, dwmw2, arnd, ming.lei, linux-arch,
	benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker

On Fri, Aug 12, 2016 at 07:04:52PM +0200, Luis R. Rodriguez wrote:
> Alright, how's this new description:
> 
> diff --git a/init/Kconfig b/init/Kconfig
> index cac3f096050d..73e4890c24c4 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -53,6 +53,34 @@ 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 "Always force building specially annotated targets"
> +	default n
> +	help
> +	  If enabled then the the special table-* Makefile targets will always
> +	  be forced to be compiled even if their respective CONFIG_ option has
> +	  been disabled, but its objects will only be linked in if the same
> +	  respective CONFIG_ option has been enabled. This helps avoid code
> +	  bit rot issues, use for these targets should be carefully considred
> +	  by maintainers. You can safely enable this option at the expense of
> +	  increasing compile time. Enabling this option helps avoid code bit
> +	  rot by taking advantage of the facilities provided and enabled by
> +	  using linker tables documented under:

As a kernel developer I have _no_ idea what this is trying to say at
all, sorry.

What is a "specially annotated target"?  Who is forcing it to be built?
What does it mean if it isn't built?

> +
> +	  include/linux/tables.h
> +
> +	  The special targets supported are:
> +
> +	    o table-obj-y
> +	    o table-lib-y

What does this mean to me as a developer?  What does it mean to a user
who wants to figure out if it should be enabled or not?

> +
> +	  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.

How does this test different subsystems?  How does disabling it not test
them?  Why would I care either way?

> +
> +	  Enabling this option never increases the size of your kernel.

Then what does it do?  Just burn electricity for no reason?

totally confused...

greg k-h

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12 20:23                         ` Greg KH
  0 siblings, 0 replies; 176+ messages in thread
From: Greg KH @ 2016-08-12 20:23 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Borislav Petkov, hpa, tglx, mingo, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, rusty, gnomes, alan, dwmw2, arnd, ming.lei, linux-arch,
	benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker, xen-devel, ak,
	pali.rohar, dvhart, platform-driver-x86, mmarek, linux, jkosina,
	korea.drzix, linux-kbuild, tony.luck, akpm, linux-ia64,
	linux-arm-kernel, linux-sh, sparclinux, catalin.marinas,
	will.deacon, rostedt, jpoimboe

On Fri, Aug 12, 2016 at 07:04:52PM +0200, Luis R. Rodriguez wrote:
> Alright, how's this new description:
> 
> diff --git a/init/Kconfig b/init/Kconfig
> index cac3f096050d..73e4890c24c4 100644
> --- a/init/Kconfig
> +++ b/init/Kconfig
> @@ -53,6 +53,34 @@ 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 "Always force building specially annotated targets"
> +	default n
> +	help
> +	  If enabled then the the special table-* Makefile targets will always
> +	  be forced to be compiled even if their respective CONFIG_ option has
> +	  been disabled, but its objects will only be linked in if the same
> +	  respective CONFIG_ option has been enabled. This helps avoid code
> +	  bit rot issues, use for these targets should be carefully considred
> +	  by maintainers. You can safely enable this option at the expense of
> +	  increasing compile time. Enabling this option helps avoid code bit
> +	  rot by taking advantage of the facilities provided and enabled by
> +	  using linker tables documented under:

As a kernel developer I have _no_ idea what this is trying to say at
all, sorry.

What is a "specially annotated target"?  Who is forcing it to be built?
What does it mean if it isn't built?

> +
> +	  include/linux/tables.h
> +
> +	  The special targets supported are:
> +
> +	    o table-obj-y
> +	    o table-lib-y

What does this mean to me as a developer?  What does it mean to a user
who wants to figure out if it should be enabled or not?

> +
> +	  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.

How does this test different subsystems?  How does disabling it not test
them?  Why would I care either way?

> +
> +	  Enabling this option never increases the size of your kernel.

Then what does it do?  Just burn electricity for no reason?

totally confused...

greg k-h

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-08-12 20:23                         ` Greg KH
  (?)
@ 2016-08-12 20:46                           ` Jiri Kosina
  -1 siblings, 0 replies; 176+ messages in thread
From: Jiri Kosina @ 2016-08-12 20:46 UTC (permalink / raw)
  To: Greg KH
  Cc: Luis R. Rodriguez, Borislav Petkov, hpa, tglx, mingo, linux,
	mhiramat, masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, rusty, gnomes, alan, dwmw2, arnd, ming.lei, linux-arch,
	benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko

On Fri, 12 Aug 2016, Greg KH wrote:

> > +	  Enabling this option never increases the size of your kernel.
> 
> Then what does it do?  Just burn electricity for no reason?

I think that this whole thing could be without loss of generality 
reformulated in a "allows for participating in compile-testing code 
efforts, without actually having to have all the compile-tested code 
present in the resulting kernel".

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12 20:46                           ` Jiri Kosina
  0 siblings, 0 replies; 176+ messages in thread
From: Jiri Kosina @ 2016-08-12 20:46 UTC (permalink / raw)
  To: Greg KH
  Cc: Luis R. Rodriguez, Borislav Petkov, hpa, tglx, mingo, linux,
	mhiramat, masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, rusty, gnomes, alan, dwmw2, arnd, ming.lei, linux-arch,
	benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko

On Fri, 12 Aug 2016, Greg KH wrote:

> > +	  Enabling this option never increases the size of your kernel.
> 
> Then what does it do?  Just burn electricity for no reason?

I think that this whole thing could be without loss of generality 
reformulated in a "allows for participating in compile-testing code 
efforts, without actually having to have all the compile-tested code 
present in the resulting kernel".

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12 20:46                           ` Jiri Kosina
  0 siblings, 0 replies; 176+ messages in thread
From: Jiri Kosina @ 2016-08-12 20:46 UTC (permalink / raw)
  To: Greg KH
  Cc: Luis R. Rodriguez, Borislav Petkov, hpa, tglx, mingo, linux,
	mhiramat, masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, rusty, gnomes, alan, dwmw2, arnd, ming.lei, linux-arch,
	benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker, xen-devel, ak,
	pali.rohar, dvhart, platform-driver-x86, mmarek, linux,
	korea.drzix, linux-kbuild, tony.luck, akpm, linux-ia64,
	linux-arm-kernel, linux-sh, sparclinux, catalin.marinas,
	will.deacon, rostedt, jpoimboe

On Fri, 12 Aug 2016, Greg KH wrote:

> > +	  Enabling this option never increases the size of your kernel.
> 
> Then what does it do?  Just burn electricity for no reason?

I think that this whole thing could be without loss of generality 
reformulated in a "allows for participating in compile-testing code 
efforts, without actually having to have all the compile-tested code 
present in the resulting kernel".

-- 
Jiri Kosina
SUSE Labs


^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-08-12 20:23                         ` Greg KH
  (?)
@ 2016-08-12 22:00                           ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-12 22:00 UTC (permalink / raw)
  To: Greg KH
  Cc: Luis R. Rodriguez, Borislav Petkov, hpa, tglx, mingo, linux,
	mhiramat, masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, rusty, gnomes, alan, dwmw2, arnd, ming.lei, linux-arch,
	benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko

On Fri, Aug 12, 2016 at 10:23:34PM +0200, Greg KH wrote:
> On Fri, Aug 12, 2016 at 07:04:52PM +0200, Luis R. Rodriguez wrote:
> > Alright, how's this new description:
> > 
> > diff --git a/init/Kconfig b/init/Kconfig
> > index cac3f096050d..73e4890c24c4 100644
> > --- a/init/Kconfig
> > +++ b/init/Kconfig
> > @@ -53,6 +53,34 @@ 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 "Always force building specially annotated targets"
> > +	default n
> > +	help
> > +	  If enabled then the the special table-* Makefile targets will always
> > +	  be forced to be compiled even if their respective CONFIG_ option has
> > +	  been disabled, but its objects will only be linked in if the same
> > +	  respective CONFIG_ option has been enabled. This helps avoid code
> > +	  bit rot issues, use for these targets should be carefully considred
> > +	  by maintainers. You can safely enable this option at the expense of
> > +	  increasing compile time. Enabling this option helps avoid code bit
> > +	  rot by taking advantage of the facilities provided and enabled by
> > +	  using linker tables documented under:
> 
> As a kernel developer I have _no_ idea what this is trying to say at
> all, sorry.

Hmm, wow OK, sorry, and I thought I was being too verbose...

OK so first, linker tables allow for the ability to help simplify initialization
sequences so that you no longer have to add the respective static inline in
header files to do nothing, instead you simply get your init routine for your
feature pegged into the linker table or not at link time. If enabling your
feature does not require structural changes, you could then safely enable
compiling this feature all the time, and only allow linking when the feature
was enabled. We don't have an easy way to express this in our build system,
the new targets added lets you accomplish this.

> What is a "specially annotated target"?

The ones listed below, table-obj-y and table-lib-y

> Who is forcing it to be built?

It would be up to maintainers for each subsystem/feature to decide if they want
to use the new targets or not within their subsystem.

> What does it mean if it isn't built?

If you have CONFIG_BUILD_AVOID_BITROT enabled and some code using the special
targets do not get built it means the dependencies it has were not met.

> > +
> > +	  include/linux/tables.h
> > +
> > +	  The special targets supported are:
> > +
> > +	    o table-obj-y
> > +	    o table-lib-y
> 
> What does this mean to me as a developer?

It mean you can count on a bit more build test coverage by
CONFIG_BUILD_AVOID_BITROT users. Using table-obj-y is functionally
equivalent to doing:

extra-y += foo.o
obj-y += foo.o

The above new targets are just short hand annotations for the same.  We could
actually use another shorthand prefix other than table-, however linker tables
help making more of these type of targets possible. For instance, on initialiation
sequences you no longer have to add each line for each feature onto a set routine,
rather you just get the initialization routine linked in or not. This lets us avoid
cluttering C code and header code with #idefs, and as a side consequences also
allows more targets to be compiled without implicating functionality.

As a developer you should take care to to use table-obj-y, or table-lib-y only if
you are certain the target does not require structural changes.

> What does it mean to a user
> who wants to figure out if it should be enabled or not?

It depends on their build system capability and their goals. If they wish
to be able to report build bugs and have a decent build system they can
enable this. Otherwise they should disable it.

> > +	  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.
> 
> How does this test different subsystems?

By enabling this feature you compile kconfig symbols that typically are
disabled by most users and which have been identified by maintainers as
needing more build testing love. The extra kconfig symbols built are
only built if the dependencies for them are met.

Maintainers for subsystems would have to identify if they have key pieces of
software that typically get disabled, and that enabling them would not incur or
require structural changes, which can use more build test love.

> How does disabling it not test them?

By disabling this feature you only compile kconfig symbols you have
enabled for your kernel.

> Why would I care either way?

You would care if you aware of certain kconfig symbols that do not
get much build test love.

> > +
> > +	  Enabling this option never increases the size of your kernel.
> 
> Then what does it do?  Just burn electricity for no reason?

It enables maintainers to annotate through the build system certain
kconfig symbol which should be built if CONFIG_BUILD_AVOID_BITROT is
enabled and its symbol dependencies are met.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12 22:00                           ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-12 22:00 UTC (permalink / raw)
  To: Greg KH
  Cc: Luis R. Rodriguez, Borislav Petkov, hpa, tglx, mingo, linux,
	mhiramat, masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, rusty, gnomes, alan, dwmw2, arnd, ming.lei, linux-arch,
	benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko

On Fri, Aug 12, 2016 at 10:23:34PM +0200, Greg KH wrote:
> On Fri, Aug 12, 2016 at 07:04:52PM +0200, Luis R. Rodriguez wrote:
> > Alright, how's this new description:
> > 
> > diff --git a/init/Kconfig b/init/Kconfig
> > index cac3f096050d..73e4890c24c4 100644
> > --- a/init/Kconfig
> > +++ b/init/Kconfig
> > @@ -53,6 +53,34 @@ 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 "Always force building specially annotated targets"
> > +	default n
> > +	help
> > +	  If enabled then the the special table-* Makefile targets will always
> > +	  be forced to be compiled even if their respective CONFIG_ option has
> > +	  been disabled, but its objects will only be linked in if the same
> > +	  respective CONFIG_ option has been enabled. This helps avoid code
> > +	  bit rot issues, use for these targets should be carefully considred
> > +	  by maintainers. You can safely enable this option at the expense of
> > +	  increasing compile time. Enabling this option helps avoid code bit
> > +	  rot by taking advantage of the facilities provided and enabled by
> > +	  using linker tables documented under:
> 
> As a kernel developer I have _no_ idea what this is trying to say at
> all, sorry.

Hmm, wow OK, sorry, and I thought I was being too verbose...

OK so first, linker tables allow for the ability to help simplify initialization
sequences so that you no longer have to add the respective static inline in
header files to do nothing, instead you simply get your init routine for your
feature pegged into the linker table or not at link time. If enabling your
feature does not require structural changes, you could then safely enable
compiling this feature all the time, and only allow linking when the feature
was enabled. We don't have an easy way to express this in our build system,
the new targets added lets you accomplish this.

> What is a "specially annotated target"?

The ones listed below, table-obj-y and table-lib-y

> Who is forcing it to be built?

It would be up to maintainers for each subsystem/feature to decide if they want
to use the new targets or not within their subsystem.

> What does it mean if it isn't built?

If you have CONFIG_BUILD_AVOID_BITROT enabled and some code using the special
targets do not get built it means the dependencies it has were not met.

> > +
> > +	  include/linux/tables.h
> > +
> > +	  The special targets supported are:
> > +
> > +	    o table-obj-y
> > +	    o table-lib-y
> 
> What does this mean to me as a developer?

It mean you can count on a bit more build test coverage by
CONFIG_BUILD_AVOID_BITROT users. Using table-obj-y is functionally
equivalent to doing:

extra-y += foo.o
obj-y += foo.o

The above new targets are just short hand annotations for the same.  We could
actually use another shorthand prefix other than table-, however linker tables
help making more of these type of targets possible. For instance, on initialiation
sequences you no longer have to add each line for each feature onto a set routine,
rather you just get the initialization routine linked in or not. This lets us avoid
cluttering C code and header code with #idefs, and as a side consequences also
allows more targets to be compiled without implicating functionality.

As a developer you should take care to to use table-obj-y, or table-lib-y only if
you are certain the target does not require structural changes.

> What does it mean to a user
> who wants to figure out if it should be enabled or not?

It depends on their build system capability and their goals. If they wish
to be able to report build bugs and have a decent build system they can
enable this. Otherwise they should disable it.

> > +	  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.
> 
> How does this test different subsystems?

By enabling this feature you compile kconfig symbols that typically are
disabled by most users and which have been identified by maintainers as
needing more build testing love. The extra kconfig symbols built are
only built if the dependencies for them are met.

Maintainers for subsystems would have to identify if they have key pieces of
software that typically get disabled, and that enabling them would not incur or
require structural changes, which can use more build test love.

> How does disabling it not test them?

By disabling this feature you only compile kconfig symbols you have
enabled for your kernel.

> Why would I care either way?

You would care if you aware of certain kconfig symbols that do not
get much build test love.

> > +
> > +	  Enabling this option never increases the size of your kernel.
> 
> Then what does it do?  Just burn electricity for no reason?

It enables maintainers to annotate through the build system certain
kconfig symbol which should be built if CONFIG_BUILD_AVOID_BITROT is
enabled and its symbol dependencies are met.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-12 22:00                           ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-12 22:00 UTC (permalink / raw)
  To: Greg KH
  Cc: Luis R. Rodriguez, Borislav Petkov, hpa, tglx, mingo, linux,
	mhiramat, masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, rusty, gnomes, alan, dwmw2, arnd, ming.lei, linux-arch,
	benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker, xen-devel, ak,
	pali.rohar, dvhart, platform-driver-x86, mmarek, linux, jkosina,
	korea.drzix, linux-kbuild, tony.luck, akpm, linux-ia64,
	linux-arm-kernel, linux-sh, sparclinux, catalin.marinas,
	will.deacon, rostedt, jpoimboe

On Fri, Aug 12, 2016 at 10:23:34PM +0200, Greg KH wrote:
> On Fri, Aug 12, 2016 at 07:04:52PM +0200, Luis R. Rodriguez wrote:
> > Alright, how's this new description:
> > 
> > diff --git a/init/Kconfig b/init/Kconfig
> > index cac3f096050d..73e4890c24c4 100644
> > --- a/init/Kconfig
> > +++ b/init/Kconfig
> > @@ -53,6 +53,34 @@ 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 "Always force building specially annotated targets"
> > +	default n
> > +	help
> > +	  If enabled then the the special table-* Makefile targets will always
> > +	  be forced to be compiled even if their respective CONFIG_ option has
> > +	  been disabled, but its objects will only be linked in if the same
> > +	  respective CONFIG_ option has been enabled. This helps avoid code
> > +	  bit rot issues, use for these targets should be carefully considred
> > +	  by maintainers. You can safely enable this option at the expense of
> > +	  increasing compile time. Enabling this option helps avoid code bit
> > +	  rot by taking advantage of the facilities provided and enabled by
> > +	  using linker tables documented under:
> 
> As a kernel developer I have _no_ idea what this is trying to say at
> all, sorry.

Hmm, wow OK, sorry, and I thought I was being too verbose...

OK so first, linker tables allow for the ability to help simplify initialization
sequences so that you no longer have to add the respective static inline in
header files to do nothing, instead you simply get your init routine for your
feature pegged into the linker table or not at link time. If enabling your
feature does not require structural changes, you could then safely enable
compiling this feature all the time, and only allow linking when the feature
was enabled. We don't have an easy way to express this in our build system,
the new targets added lets you accomplish this.

> What is a "specially annotated target"?

The ones listed below, table-obj-y and table-lib-y

> Who is forcing it to be built?

It would be up to maintainers for each subsystem/feature to decide if they want
to use the new targets or not within their subsystem.

> What does it mean if it isn't built?

If you have CONFIG_BUILD_AVOID_BITROT enabled and some code using the special
targets do not get built it means the dependencies it has were not met.

> > +
> > +	  include/linux/tables.h
> > +
> > +	  The special targets supported are:
> > +
> > +	    o table-obj-y
> > +	    o table-lib-y
> 
> What does this mean to me as a developer?

It mean you can count on a bit more build test coverage by
CONFIG_BUILD_AVOID_BITROT users. Using table-obj-y is functionally
equivalent to doing:

extra-y += foo.o
obj-y += foo.o

The above new targets are just short hand annotations for the same.  We could
actually use another shorthand prefix other than table-, however linker tables
help making more of these type of targets possible. For instance, on initialiation
sequences you no longer have to add each line for each feature onto a set routine,
rather you just get the initialization routine linked in or not. This lets us avoid
cluttering C code and header code with #idefs, and as a side consequences also
allows more targets to be compiled without implicating functionality.

As a developer you should take care to to use table-obj-y, or table-lib-y only if
you are certain the target does not require structural changes.

> What does it mean to a user
> who wants to figure out if it should be enabled or not?

It depends on their build system capability and their goals. If they wish
to be able to report build bugs and have a decent build system they can
enable this. Otherwise they should disable it.

> > +	  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.
> 
> How does this test different subsystems?

By enabling this feature you compile kconfig symbols that typically are
disabled by most users and which have been identified by maintainers as
needing more build testing love. The extra kconfig symbols built are
only built if the dependencies for them are met.

Maintainers for subsystems would have to identify if they have key pieces of
software that typically get disabled, and that enabling them would not incur or
require structural changes, which can use more build test love.

> How does disabling it not test them?

By disabling this feature you only compile kconfig symbols you have
enabled for your kernel.

> Why would I care either way?

You would care if you aware of certain kconfig symbols that do not
get much build test love.

> > +
> > +	  Enabling this option never increases the size of your kernel.
> 
> Then what does it do?  Just burn electricity for no reason?

It enables maintainers to annotate through the build system certain
kconfig symbol which should be built if CONFIG_BUILD_AVOID_BITROT is
enabled and its symbol dependencies are met.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-08-12 22:00                           ` Luis R. Rodriguez
  (?)
@ 2016-08-13 10:46                             ` Greg KH
  -1 siblings, 0 replies; 176+ messages in thread
From: Greg KH @ 2016-08-13 10:46 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Borislav Petkov, hpa, tglx, mingo, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, rusty, gnomes, alan, dwmw2, arnd, ming.lei, linux-arch,
	benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker

On Sat, Aug 13, 2016 at 12:00:42AM +0200, Luis R. Rodriguez wrote:
> On Fri, Aug 12, 2016 at 10:23:34PM +0200, Greg KH wrote:
> > On Fri, Aug 12, 2016 at 07:04:52PM +0200, Luis R. Rodriguez wrote:
> > > Alright, how's this new description:
> > > 
> > > diff --git a/init/Kconfig b/init/Kconfig
> > > index cac3f096050d..73e4890c24c4 100644
> > > --- a/init/Kconfig
> > > +++ b/init/Kconfig
> > > @@ -53,6 +53,34 @@ 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 "Always force building specially annotated targets"
> > > +	default n
> > > +	help
> > > +	  If enabled then the the special table-* Makefile targets will always
> > > +	  be forced to be compiled even if their respective CONFIG_ option has
> > > +	  been disabled, but its objects will only be linked in if the same
> > > +	  respective CONFIG_ option has been enabled. This helps avoid code
> > > +	  bit rot issues, use for these targets should be carefully considred
> > > +	  by maintainers. You can safely enable this option at the expense of
> > > +	  increasing compile time. Enabling this option helps avoid code bit
> > > +	  rot by taking advantage of the facilities provided and enabled by
> > > +	  using linker tables documented under:
> > 
> > As a kernel developer I have _no_ idea what this is trying to say at
> > all, sorry.
> 
> Hmm, wow OK, sorry, and I thought I was being too verbose...

All of your good explainations and detail need to go into the text
itself.  Responding to my questions is wonderful, but is not going to
help anyone out who sees the config option for the first time, unless
you change the text there.

> OK so first, linker tables allow for the ability to help simplify initialization
> sequences so that you no longer have to add the respective static inline in
> header files to do nothing, instead you simply get your init routine for your
> feature pegged into the linker table or not at link time. If enabling your
> feature does not require structural changes, you could then safely enable
> compiling this feature all the time, and only allow linking when the feature
> was enabled. We don't have an easy way to express this in our build system,
> the new targets added lets you accomplish this.

I still don't understand, sorry.

As a kernel developer, why do I care about this?  Who should care about
this, a driver developer, subsystem developer, someone adding a syscall,
an arch subsystem developer?

> > What is a "specially annotated target"?
> 
> The ones listed below, table-obj-y and table-lib-y

circular logic doesn't work :)

> > Who is forcing it to be built?
> 
> It would be up to maintainers for each subsystem/feature to decide if they want
> to use the new targets or not within their subsystem.

Ok, as a maintainer of a subsystem, I still have no idea what any of
this means.  But maybe I'm just don't understand kernel subsystem
development...

> > What does it mean if it isn't built?
> 
> If you have CONFIG_BUILD_AVOID_BITROT enabled and some code using the special
> targets do not get built it means the dependencies it has were not met.

What "dependencies"?

> > > +
> > > +	  include/linux/tables.h
> > > +
> > > +	  The special targets supported are:
> > > +
> > > +	    o table-obj-y
> > > +	    o table-lib-y
> > 
> > What does this mean to me as a developer?
> 
> It mean you can count on a bit more build test coverage by
> CONFIG_BUILD_AVOID_BITROT users. Using table-obj-y is functionally
> equivalent to doing:
> 
> extra-y += foo.o
> obj-y += foo.o

Ok, but why change this?  What's the advantage?  Are you going to now go
and change all locations of the above in the tree to the table-
versions?  If not, why is this needed?

> The above new targets are just short hand annotations for the same.  We could
> actually use another shorthand prefix other than table-, however linker tables
> help making more of these type of targets possible. For instance, on initialiation
> sequences you no longer have to add each line for each feature onto a set routine,
> rather you just get the initialization routine linked in or not. This lets us avoid
> cluttering C code and header code with #idefs, and as a side consequences also
> allows more targets to be compiled without implicating functionality.
> 
> As a developer you should take care to to use table-obj-y, or table-lib-y only if
> you are certain the target does not require structural changes.

How am I supposed to be "certain"?

> > What does it mean to a user
> > who wants to figure out if it should be enabled or not?
> 
> It depends on their build system capability and their goals. If they wish
> to be able to report build bugs and have a decent build system they can
> enable this. Otherwise they should disable it.

Why is this differnent from CONFIG_TEST build option we have today (or
whatever it's called...)

Anyway, again, I have no idea what this is, nor how I should use it.
And if I am the audience for this type of config option, well, perhaps
it needs to be rethought...

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-13 10:46                             ` Greg KH
  0 siblings, 0 replies; 176+ messages in thread
From: Greg KH @ 2016-08-13 10:46 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Borislav Petkov, hpa, tglx, mingo, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, rusty, gnomes, alan, dwmw2, arnd, ming.lei, linux-arch,
	benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker

On Sat, Aug 13, 2016 at 12:00:42AM +0200, Luis R. Rodriguez wrote:
> On Fri, Aug 12, 2016 at 10:23:34PM +0200, Greg KH wrote:
> > On Fri, Aug 12, 2016 at 07:04:52PM +0200, Luis R. Rodriguez wrote:
> > > Alright, how's this new description:
> > > 
> > > diff --git a/init/Kconfig b/init/Kconfig
> > > index cac3f096050d..73e4890c24c4 100644
> > > --- a/init/Kconfig
> > > +++ b/init/Kconfig
> > > @@ -53,6 +53,34 @@ 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 "Always force building specially annotated targets"
> > > +	default n
> > > +	help
> > > +	  If enabled then the the special table-* Makefile targets will always
> > > +	  be forced to be compiled even if their respective CONFIG_ option has
> > > +	  been disabled, but its objects will only be linked in if the same
> > > +	  respective CONFIG_ option has been enabled. This helps avoid code
> > > +	  bit rot issues, use for these targets should be carefully considred
> > > +	  by maintainers. You can safely enable this option at the expense of
> > > +	  increasing compile time. Enabling this option helps avoid code bit
> > > +	  rot by taking advantage of the facilities provided and enabled by
> > > +	  using linker tables documented under:
> > 
> > As a kernel developer I have _no_ idea what this is trying to say at
> > all, sorry.
> 
> Hmm, wow OK, sorry, and I thought I was being too verbose...

All of your good explainations and detail need to go into the text
itself.  Responding to my questions is wonderful, but is not going to
help anyone out who sees the config option for the first time, unless
you change the text there.

> OK so first, linker tables allow for the ability to help simplify initialization
> sequences so that you no longer have to add the respective static inline in
> header files to do nothing, instead you simply get your init routine for your
> feature pegged into the linker table or not at link time. If enabling your
> feature does not require structural changes, you could then safely enable
> compiling this feature all the time, and only allow linking when the feature
> was enabled. We don't have an easy way to express this in our build system,
> the new targets added lets you accomplish this.

I still don't understand, sorry.

As a kernel developer, why do I care about this?  Who should care about
this, a driver developer, subsystem developer, someone adding a syscall,
an arch subsystem developer?

> > What is a "specially annotated target"?
> 
> The ones listed below, table-obj-y and table-lib-y

circular logic doesn't work :)

> > Who is forcing it to be built?
> 
> It would be up to maintainers for each subsystem/feature to decide if they want
> to use the new targets or not within their subsystem.

Ok, as a maintainer of a subsystem, I still have no idea what any of
this means.  But maybe I'm just don't understand kernel subsystem
development...

> > What does it mean if it isn't built?
> 
> If you have CONFIG_BUILD_AVOID_BITROT enabled and some code using the special
> targets do not get built it means the dependencies it has were not met.

What "dependencies"?

> > > +
> > > +	  include/linux/tables.h
> > > +
> > > +	  The special targets supported are:
> > > +
> > > +	    o table-obj-y
> > > +	    o table-lib-y
> > 
> > What does this mean to me as a developer?
> 
> It mean you can count on a bit more build test coverage by
> CONFIG_BUILD_AVOID_BITROT users. Using table-obj-y is functionally
> equivalent to doing:
> 
> extra-y += foo.o
> obj-y += foo.o

Ok, but why change this?  What's the advantage?  Are you going to now go
and change all locations of the above in the tree to the table-
versions?  If not, why is this needed?

> The above new targets are just short hand annotations for the same.  We could
> actually use another shorthand prefix other than table-, however linker tables
> help making more of these type of targets possible. For instance, on initialiation
> sequences you no longer have to add each line for each feature onto a set routine,
> rather you just get the initialization routine linked in or not. This lets us avoid
> cluttering C code and header code with #idefs, and as a side consequences also
> allows more targets to be compiled without implicating functionality.
> 
> As a developer you should take care to to use table-obj-y, or table-lib-y only if
> you are certain the target does not require structural changes.

How am I supposed to be "certain"?

> > What does it mean to a user
> > who wants to figure out if it should be enabled or not?
> 
> It depends on their build system capability and their goals. If they wish
> to be able to report build bugs and have a decent build system they can
> enable this. Otherwise they should disable it.

Why is this differnent from CONFIG_TEST build option we have today (or
whatever it's called...)

Anyway, again, I have no idea what this is, nor how I should use it.
And if I am the audience for this type of config option, well, perhaps
it needs to be rethought...

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-13 10:46                             ` Greg KH
  0 siblings, 0 replies; 176+ messages in thread
From: Greg KH @ 2016-08-13 10:46 UTC (permalink / raw)
  To: Luis R. Rodriguez
  Cc: Borislav Petkov, hpa, tglx, mingo, linux, mhiramat,
	masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, rusty, gnomes, alan, dwmw2, arnd, ming.lei, linux-arch,
	benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker, xen-devel, ak,
	pali.rohar, dvhart, platform-driver-x86, mmarek, linux, jkosina,
	korea.drzix, linux-kbuild, tony.luck, akpm, linux-ia64,
	linux-arm-kernel, linux-sh, sparclinux, catalin.marinas,
	will.deacon, rostedt, jpoimboe

On Sat, Aug 13, 2016 at 12:00:42AM +0200, Luis R. Rodriguez wrote:
> On Fri, Aug 12, 2016 at 10:23:34PM +0200, Greg KH wrote:
> > On Fri, Aug 12, 2016 at 07:04:52PM +0200, Luis R. Rodriguez wrote:
> > > Alright, how's this new description:
> > > 
> > > diff --git a/init/Kconfig b/init/Kconfig
> > > index cac3f096050d..73e4890c24c4 100644
> > > --- a/init/Kconfig
> > > +++ b/init/Kconfig
> > > @@ -53,6 +53,34 @@ 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 "Always force building specially annotated targets"
> > > +	default n
> > > +	help
> > > +	  If enabled then the the special table-* Makefile targets will always
> > > +	  be forced to be compiled even if their respective CONFIG_ option has
> > > +	  been disabled, but its objects will only be linked in if the same
> > > +	  respective CONFIG_ option has been enabled. This helps avoid code
> > > +	  bit rot issues, use for these targets should be carefully considred
> > > +	  by maintainers. You can safely enable this option at the expense of
> > > +	  increasing compile time. Enabling this option helps avoid code bit
> > > +	  rot by taking advantage of the facilities provided and enabled by
> > > +	  using linker tables documented under:
> > 
> > As a kernel developer I have _no_ idea what this is trying to say at
> > all, sorry.
> 
> Hmm, wow OK, sorry, and I thought I was being too verbose...

All of your good explainations and detail need to go into the text
itself.  Responding to my questions is wonderful, but is not going to
help anyone out who sees the config option for the first time, unless
you change the text there.

> OK so first, linker tables allow for the ability to help simplify initialization
> sequences so that you no longer have to add the respective static inline in
> header files to do nothing, instead you simply get your init routine for your
> feature pegged into the linker table or not at link time. If enabling your
> feature does not require structural changes, you could then safely enable
> compiling this feature all the time, and only allow linking when the feature
> was enabled. We don't have an easy way to express this in our build system,
> the new targets added lets you accomplish this.

I still don't understand, sorry.

As a kernel developer, why do I care about this?  Who should care about
this, a driver developer, subsystem developer, someone adding a syscall,
an arch subsystem developer?

> > What is a "specially annotated target"?
> 
> The ones listed below, table-obj-y and table-lib-y

circular logic doesn't work :)

> > Who is forcing it to be built?
> 
> It would be up to maintainers for each subsystem/feature to decide if they want
> to use the new targets or not within their subsystem.

Ok, as a maintainer of a subsystem, I still have no idea what any of
this means.  But maybe I'm just don't understand kernel subsystem
development...

> > What does it mean if it isn't built?
> 
> If you have CONFIG_BUILD_AVOID_BITROT enabled and some code using the special
> targets do not get built it means the dependencies it has were not met.

What "dependencies"?

> > > +
> > > +	  include/linux/tables.h
> > > +
> > > +	  The special targets supported are:
> > > +
> > > +	    o table-obj-y
> > > +	    o table-lib-y
> > 
> > What does this mean to me as a developer?
> 
> It mean you can count on a bit more build test coverage by
> CONFIG_BUILD_AVOID_BITROT users. Using table-obj-y is functionally
> equivalent to doing:
> 
> extra-y += foo.o
> obj-y += foo.o

Ok, but why change this?  What's the advantage?  Are you going to now go
and change all locations of the above in the tree to the table-
versions?  If not, why is this needed?

> The above new targets are just short hand annotations for the same.  We could
> actually use another shorthand prefix other than table-, however linker tables
> help making more of these type of targets possible. For instance, on initialiation
> sequences you no longer have to add each line for each feature onto a set routine,
> rather you just get the initialization routine linked in or not. This lets us avoid
> cluttering C code and header code with #idefs, and as a side consequences also
> allows more targets to be compiled without implicating functionality.
> 
> As a developer you should take care to to use table-obj-y, or table-lib-y only if
> you are certain the target does not require structural changes.

How am I supposed to be "certain"?

> > What does it mean to a user
> > who wants to figure out if it should be enabled or not?
> 
> It depends on their build system capability and their goals. If they wish
> to be able to report build bugs and have a decent build system they can
> enable this. Otherwise they should disable it.

Why is this differnent from CONFIG_TEST build option we have today (or
whatever it's called...)

Anyway, again, I have no idea what this is, nor how I should use it.
And if I am the audience for this type of config option, well, perhaps
it needs to be rethought...

thanks,

greg k-h

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
  2016-08-13 10:46                             ` Greg KH
  (?)
@ 2016-08-13 17:54                               ` Luis R. Rodriguez
  -1 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-13 17:54 UTC (permalink / raw)
  To: Greg KH
  Cc: gnomes, linux-ia64, jkosina, benh, ming.lei, heiko.carstens,
	platform-driver-x86, paul.gortmaker, hpa, masami.hiramatsu.pt,
	linux-arch, sparclinux, xen-devel, linux, linux-sh, will.deacon,
	korea.drzix, x86, anil.s.keshavamurthy, fontana, mingo,
	linux-arm-kernel, catalin.marinas, dvhart, david.vrabel,
	pali.rohar, keescook, arnd, realmz6, linux, rusty, rostedt,
	christopher.denicolo, jbaron, ananth, Borislav

On Sat, Aug 13, 2016 at 12:46:16PM +0200, Greg KH wrote:
> On Sat, Aug 13, 2016 at 12:00:42AM +0200, Luis R. Rodriguez wrote:
> > On Fri, Aug 12, 2016 at 10:23:34PM +0200, Greg KH wrote:
> > > On Fri, Aug 12, 2016 at 07:04:52PM +0200, Luis R. Rodriguez wrote:
> > > > Alright, how's this new description:
> > > > 
> > > > diff --git a/init/Kconfig b/init/Kconfig
> > > > index cac3f096050d..73e4890c24c4 100644
> > > > --- a/init/Kconfig
> > > > +++ b/init/Kconfig
> > > > @@ -53,6 +53,34 @@ 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 "Always force building specially annotated targets"
> > > > +	default n
> > > > +	help
> > > > +	  If enabled then the the special table-* Makefile targets will always
> > > > +	  be forced to be compiled even if their respective CONFIG_ option has
> > > > +	  been disabled, but its objects will only be linked in if the same
> > > > +	  respective CONFIG_ option has been enabled. This helps avoid code
> > > > +	  bit rot issues, use for these targets should be carefully considred
> > > > +	  by maintainers. You can safely enable this option at the expense of
> > > > +	  increasing compile time. Enabling this option helps avoid code bit
> > > > +	  rot by taking advantage of the facilities provided and enabled by
> > > > +	  using linker tables documented under:
> > > 
> > > As a kernel developer I have _no_ idea what this is trying to say at
> > > all, sorry.
> > 
> > Hmm, wow OK, sorry, and I thought I was being too verbose...
> 
> All of your good explainations and detail need to go into the text
> itself.  Responding to my questions is wonderful, but is not going to
> help anyone out who sees the config option for the first time, unless
> you change the text there.

Sure.

> > OK so first, linker tables allow for the ability to help simplify initialization
> > sequences so that you no longer have to add the respective static inline in
> > header files to do nothing, instead you simply get your init routine for your
> > feature pegged into the linker table or not at link time. If enabling your
> > feature does not require structural changes, you could then safely enable
> > compiling this feature all the time, and only allow linking when the feature
> > was enabled. We don't have an easy way to express this in our build system,
> > the new targets added lets you accomplish this.
> 
> I still don't understand, sorry.
> 
> As a kernel developer, why do I care about this?  Who should care about
> this, a driver developer, subsystem developer, someone adding a syscall,
> an arch subsystem developer?

I'll try to explain this more.

> > > What is a "specially annotated target"?
> > 
> > The ones listed below, table-obj-y and table-lib-y
> 
> circular logic doesn't work :)
> 
> > > Who is forcing it to be built?
> > 
> > It would be up to maintainers for each subsystem/feature to decide if they want
> > to use the new targets or not within their subsystem.
> 
> Ok, as a maintainer of a subsystem, I still have no idea what any of
> this means.  But maybe I'm just don't understand kernel subsystem
> development...

Jeesh, OK, will give it one more go.

> > > What does it mean if it isn't built?
> > 
> > If you have CONFIG_BUILD_AVOID_BITROT enabled and some code using the special
> > targets do not get built it means the dependencies it has were not met.
> 
> What "dependencies"?

Will elaborate.

> > > > +
> > > > +	  include/linux/tables.h
> > > > +
> > > > +	  The special targets supported are:
> > > > +
> > > > +	    o table-obj-y
> > > > +	    o table-lib-y
> > > 
> > > What does this mean to me as a developer?
> > 
> > It mean you can count on a bit more build test coverage by
> > CONFIG_BUILD_AVOID_BITROT users. Using table-obj-y is functionally
> > equivalent to doing:
> > 
> > extra-y += foo.o
> > obj-y += foo.o
> 
> Ok, but why change this?  What's the advantage?  Are you going to now go
> and change all locations of the above in the tree to the table-
> versions?  If not, why is this needed?

Hell no, the gain here is clear annotation of when this practice is used.
Linker table use could make this practice more prevalent.

> > The above new targets are just short hand annotations for the same.  We could
> > actually use another shorthand prefix other than table-, however linker tables
> > help making more of these type of targets possible. For instance, on initialiation
> > sequences you no longer have to add each line for each feature onto a set routine,
> > rather you just get the initialization routine linked in or not. This lets us avoid
> > cluttering C code and header code with #idefs, and as a side consequences also
> > allows more targets to be compiled without implicating functionality.
> > 
> > As a developer you should take care to to use table-obj-y, or table-lib-y only if
> > you are certain the target does not require structural changes.
> 
> How am I supposed to be "certain"?

Compile testing is one easy way, but better yet understanding the code is
best. The structural change complication was one consideration that came
to mind.

> > > What does it mean to a user
> > > who wants to figure out if it should be enabled or not?
> > 
> > It depends on their build system capability and their goals. If they wish
> > to be able to report build bugs and have a decent build system they can
> > enable this. Otherwise they should disable it.
> 
> Why is this differnent from CONFIG_TEST build option we have today (or
> whatever it's called...)

We could fold it under that, sure.

> Anyway, again, I have no idea what this is, nor how I should use it.
> And if I am the audience for this type of config option, well, perhaps
> it needs to be rethought...

Alright, I'll rip all this code bit rot things out into its own separate
patch for Kbuild changes, documentation, etc, and see if this helps. Otherwise
we can evaluate if we should just drop it. Keep in mind that iPXE actually
used it for this purpose and enabled it tree wide, since I knew it would
likely not be a popular option for some I figured an optional build target
would be better. The rest is up to me to try to explain then how and why some
folks might want this. Linker tables just make it an easier practice to
use due to the simplication of code from #ifdef statements on Kconfig
symbols.

I'll address all this then separately in my next respin. It will be its own
separate patch.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-13 17:54                               ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-13 17:54 UTC (permalink / raw)
  To: Greg KH
  Cc: gnomes, linux-ia64, jkosina, benh, ming.lei, heiko.carstens,
	platform-driver-x86, paul.gortmaker, hpa, masami.hiramatsu.pt,
	linux-arch, sparclinux, xen-devel, linux, linux-sh, will.deacon,
	korea.drzix, x86, anil.s.keshavamurthy, fontana, mingo,
	linux-arm-kernel, catalin.marinas, dvhart, david.vrabel,
	pali.rohar, keescook, arnd, realmz6, linux, rusty, rostedt,
	christopher.denicolo, jbaron, ananth, Borislav

On Sat, Aug 13, 2016 at 12:46:16PM +0200, Greg KH wrote:
> On Sat, Aug 13, 2016 at 12:00:42AM +0200, Luis R. Rodriguez wrote:
> > On Fri, Aug 12, 2016 at 10:23:34PM +0200, Greg KH wrote:
> > > On Fri, Aug 12, 2016 at 07:04:52PM +0200, Luis R. Rodriguez wrote:
> > > > Alright, how's this new description:
> > > > 
> > > > diff --git a/init/Kconfig b/init/Kconfig
> > > > index cac3f096050d..73e4890c24c4 100644
> > > > --- a/init/Kconfig
> > > > +++ b/init/Kconfig
> > > > @@ -53,6 +53,34 @@ 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 "Always force building specially annotated targets"
> > > > +	default n
> > > > +	help
> > > > +	  If enabled then the the special table-* Makefile targets will always
> > > > +	  be forced to be compiled even if their respective CONFIG_ option has
> > > > +	  been disabled, but its objects will only be linked in if the same
> > > > +	  respective CONFIG_ option has been enabled. This helps avoid code
> > > > +	  bit rot issues, use for these targets should be carefully considred
> > > > +	  by maintainers. You can safely enable this option at the expense of
> > > > +	  increasing compile time. Enabling this option helps avoid code bit
> > > > +	  rot by taking advantage of the facilities provided and enabled by
> > > > +	  using linker tables documented under:
> > > 
> > > As a kernel developer I have _no_ idea what this is trying to say at
> > > all, sorry.
> > 
> > Hmm, wow OK, sorry, and I thought I was being too verbose...
> 
> All of your good explainations and detail need to go into the text
> itself.  Responding to my questions is wonderful, but is not going to
> help anyone out who sees the config option for the first time, unless
> you change the text there.

Sure.

> > OK so first, linker tables allow for the ability to help simplify initialization
> > sequences so that you no longer have to add the respective static inline in
> > header files to do nothing, instead you simply get your init routine for your
> > feature pegged into the linker table or not at link time. If enabling your
> > feature does not require structural changes, you could then safely enable
> > compiling this feature all the time, and only allow linking when the feature
> > was enabled. We don't have an easy way to express this in our build system,
> > the new targets added lets you accomplish this.
> 
> I still don't understand, sorry.
> 
> As a kernel developer, why do I care about this?  Who should care about
> this, a driver developer, subsystem developer, someone adding a syscall,
> an arch subsystem developer?

I'll try to explain this more.

> > > What is a "specially annotated target"?
> > 
> > The ones listed below, table-obj-y and table-lib-y
> 
> circular logic doesn't work :)
> 
> > > Who is forcing it to be built?
> > 
> > It would be up to maintainers for each subsystem/feature to decide if they want
> > to use the new targets or not within their subsystem.
> 
> Ok, as a maintainer of a subsystem, I still have no idea what any of
> this means.  But maybe I'm just don't understand kernel subsystem
> development...

Jeesh, OK, will give it one more go.

> > > What does it mean if it isn't built?
> > 
> > If you have CONFIG_BUILD_AVOID_BITROT enabled and some code using the special
> > targets do not get built it means the dependencies it has were not met.
> 
> What "dependencies"?

Will elaborate.

> > > > +
> > > > +	  include/linux/tables.h
> > > > +
> > > > +	  The special targets supported are:
> > > > +
> > > > +	    o table-obj-y
> > > > +	    o table-lib-y
> > > 
> > > What does this mean to me as a developer?
> > 
> > It mean you can count on a bit more build test coverage by
> > CONFIG_BUILD_AVOID_BITROT users. Using table-obj-y is functionally
> > equivalent to doing:
> > 
> > extra-y += foo.o
> > obj-y += foo.o
> 
> Ok, but why change this?  What's the advantage?  Are you going to now go
> and change all locations of the above in the tree to the table-
> versions?  If not, why is this needed?

Hell no, the gain here is clear annotation of when this practice is used.
Linker table use could make this practice more prevalent.

> > The above new targets are just short hand annotations for the same.  We could
> > actually use another shorthand prefix other than table-, however linker tables
> > help making more of these type of targets possible. For instance, on initialiation
> > sequences you no longer have to add each line for each feature onto a set routine,
> > rather you just get the initialization routine linked in or not. This lets us avoid
> > cluttering C code and header code with #idefs, and as a side consequences also
> > allows more targets to be compiled without implicating functionality.
> > 
> > As a developer you should take care to to use table-obj-y, or table-lib-y only if
> > you are certain the target does not require structural changes.
> 
> How am I supposed to be "certain"?

Compile testing is one easy way, but better yet understanding the code is
best. The structural change complication was one consideration that came
to mind.

> > > What does it mean to a user
> > > who wants to figure out if it should be enabled or not?
> > 
> > It depends on their build system capability and their goals. If they wish
> > to be able to report build bugs and have a decent build system they can
> > enable this. Otherwise they should disable it.
> 
> Why is this differnent from CONFIG_TEST build option we have today (or
> whatever it's called...)

We could fold it under that, sure.

> Anyway, again, I have no idea what this is, nor how I should use it.
> And if I am the audience for this type of config option, well, perhaps
> it needs to be rethought...

Alright, I'll rip all this code bit rot things out into its own separate
patch for Kbuild changes, documentation, etc, and see if this helps. Otherwise
we can evaluate if we should just drop it. Keep in mind that iPXE actually
used it for this purpose and enabled it tree wide, since I knew it would
likely not be a popular option for some I figured an optional build target
would be better. The rest is up to me to try to explain then how and why some
folks might want this. Linker tables just make it an easier practice to
use due to the simplication of code from #ifdef statements on Kconfig
symbols.

I'll address all this then separately in my next respin. It will be its own
separate patch.

  Luis

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 07/13] tables.h: add linker table support
@ 2016-08-13 17:54                               ` Luis R. Rodriguez
  0 siblings, 0 replies; 176+ messages in thread
From: Luis R. Rodriguez @ 2016-08-13 17:54 UTC (permalink / raw)
  To: Greg KH
  Cc: Luis R. Rodriguez, Borislav Petkov, hpa, tglx, mingo, linux,
	mhiramat, masami.hiramatsu.pt, jbaron, heiko.carstens, ananth,
	anil.s.keshavamurthy, davem, realmz6, x86, luto, keescook,
	torvalds, rusty, gnomes, alan, dwmw2, arnd, ming.lei, linux-arch,
	benh, ananth, pebolle, fontana, ciaran.farrell,
	christopher.denicolo, david.vrabel, konrad.wilk, mcb30, jgross,
	andrew.cooper3, andriy.shevchenko, paul.gortmaker, xen-devel, ak,
	pali.rohar, dvhart, platform-driver-x86, mmarek, linux, jkosina,
	korea.drzix, linux-kbuild, tony.luck, akpm, linux-ia64,
	linux-arm-kernel, linux-sh, sparclinux, catalin.marinas,
	will.deacon, rostedt, jpoimboe

On Sat, Aug 13, 2016 at 12:46:16PM +0200, Greg KH wrote:
> On Sat, Aug 13, 2016 at 12:00:42AM +0200, Luis R. Rodriguez wrote:
> > On Fri, Aug 12, 2016 at 10:23:34PM +0200, Greg KH wrote:
> > > On Fri, Aug 12, 2016 at 07:04:52PM +0200, Luis R. Rodriguez wrote:
> > > > Alright, how's this new description:
> > > > 
> > > > diff --git a/init/Kconfig b/init/Kconfig
> > > > index cac3f096050d..73e4890c24c4 100644
> > > > --- a/init/Kconfig
> > > > +++ b/init/Kconfig
> > > > @@ -53,6 +53,34 @@ 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 "Always force building specially annotated targets"
> > > > +	default n
> > > > +	help
> > > > +	  If enabled then the the special table-* Makefile targets will always
> > > > +	  be forced to be compiled even if their respective CONFIG_ option has
> > > > +	  been disabled, but its objects will only be linked in if the same
> > > > +	  respective CONFIG_ option has been enabled. This helps avoid code
> > > > +	  bit rot issues, use for these targets should be carefully considred
> > > > +	  by maintainers. You can safely enable this option at the expense of
> > > > +	  increasing compile time. Enabling this option helps avoid code bit
> > > > +	  rot by taking advantage of the facilities provided and enabled by
> > > > +	  using linker tables documented under:
> > > 
> > > As a kernel developer I have _no_ idea what this is trying to say at
> > > all, sorry.
> > 
> > Hmm, wow OK, sorry, and I thought I was being too verbose...
> 
> All of your good explainations and detail need to go into the text
> itself.  Responding to my questions is wonderful, but is not going to
> help anyone out who sees the config option for the first time, unless
> you change the text there.

Sure.

> > OK so first, linker tables allow for the ability to help simplify initialization
> > sequences so that you no longer have to add the respective static inline in
> > header files to do nothing, instead you simply get your init routine for your
> > feature pegged into the linker table or not at link time. If enabling your
> > feature does not require structural changes, you could then safely enable
> > compiling this feature all the time, and only allow linking when the feature
> > was enabled. We don't have an easy way to express this in our build system,
> > the new targets added lets you accomplish this.
> 
> I still don't understand, sorry.
> 
> As a kernel developer, why do I care about this?  Who should care about
> this, a driver developer, subsystem developer, someone adding a syscall,
> an arch subsystem developer?

I'll try to explain this more.

> > > What is a "specially annotated target"?
> > 
> > The ones listed below, table-obj-y and table-lib-y
> 
> circular logic doesn't work :)
> 
> > > Who is forcing it to be built?
> > 
> > It would be up to maintainers for each subsystem/feature to decide if they want
> > to use the new targets or not within their subsystem.
> 
> Ok, as a maintainer of a subsystem, I still have no idea what any of
> this means.  But maybe I'm just don't understand kernel subsystem
> development...

Jeesh, OK, will give it one more go.

> > > What does it mean if it isn't built?
> > 
> > If you have CONFIG_BUILD_AVOID_BITROT enabled and some code using the special
> > targets do not get built it means the dependencies it has were not met.
> 
> What "dependencies"?

Will elaborate.

> > > > +
> > > > +	  include/linux/tables.h
> > > > +
> > > > +	  The special targets supported are:
> > > > +
> > > > +	    o table-obj-y
> > > > +	    o table-lib-y
> > > 
> > > What does this mean to me as a developer?
> > 
> > It mean you can count on a bit more build test coverage by
> > CONFIG_BUILD_AVOID_BITROT users. Using table-obj-y is functionally
> > equivalent to doing:
> > 
> > extra-y += foo.o
> > obj-y += foo.o
> 
> Ok, but why change this?  What's the advantage?  Are you going to now go
> and change all locations of the above in the tree to the table-
> versions?  If not, why is this needed?

Hell no, the gain here is clear annotation of when this practice is used.
Linker table use could make this practice more prevalent.

> > The above new targets are just short hand annotations for the same.  We could
> > actually use another shorthand prefix other than table-, however linker tables
> > help making more of these type of targets possible. For instance, on initialiation
> > sequences you no longer have to add each line for each feature onto a set routine,
> > rather you just get the initialization routine linked in or not. This lets us avoid
> > cluttering C code and header code with #idefs, and as a side consequences also
> > allows more targets to be compiled without implicating functionality.
> > 
> > As a developer you should take care to to use table-obj-y, or table-lib-y only if
> > you are certain the target does not require structural changes.
> 
> How am I supposed to be "certain"?

Compile testing is one easy way, but better yet understanding the code is
best. The structural change complication was one consideration that came
to mind.

> > > What does it mean to a user
> > > who wants to figure out if it should be enabled or not?
> > 
> > It depends on their build system capability and their goals. If they wish
> > to be able to report build bugs and have a decent build system they can
> > enable this. Otherwise they should disable it.
> 
> Why is this differnent from CONFIG_TEST build option we have today (or
> whatever it's called...)

We could fold it under that, sure.

> Anyway, again, I have no idea what this is, nor how I should use it.
> And if I am the audience for this type of config option, well, perhaps
> it needs to be rethought...

Alright, I'll rip all this code bit rot things out into its own separate
patch for Kbuild changes, documentation, etc, and see if this helps. Otherwise
we can evaluate if we should just drop it. Keep in mind that iPXE actually
used it for this purpose and enabled it tree wide, since I knew it would
likely not be a popular option for some I figured an optional build target
would be better. The rest is up to me to try to explain then how and why some
folks might want this. Linker tables just make it an easier practice to
use due to the simplication of code from #ifdef statements on Kconfig
symbols.

I'll address all this then separately in my next respin. It will be its own
separate patch.

  Luis

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-08-15 20:15         ` Alan Cox
  0 siblings, 0 replies; 176+ messages in thread
From: Alan Cox @ 2016-08-15 20:15 UTC (permalink / raw)
  To: Andy Lutomirski, James Bottomley
  Cc: One Thousand Gnomes, linux-ia64, realmz6, linux-sh, benh,
	ming.lei, heiko.carstens, linux, platform-driver-x86,
	paul.gortmaker, hpa, masami.hiramatsu.pt, linux-arch, sparclinux,
	xen-devel, linux, x86, anil.s.keshavamurthy, fontana, mingo,
	catalin.marinas, dvhart, dwmw2, mhiramat, rusty, keescook, arnd,
	linux-kbuild, will.deacon, pali.rohar, rostedt,
	christopher.denicolo, jbaron, ananth, ciaran.farrell


[-- Attachment #1.1: Type: text/plain, Size: 482 bytes --]


> This is the module tag ... it says what licence the module is under,
> not the licence for the module combined with the kernel, which is
> always GPLv2 because the stricter licence rules.

Because if I build a BSD licensed module against the kernel, give you
the binaries and refuse to give you the source I am conforming to the
BSD licence in letter. So to use it with the kernel it needs to be GPL
with additional rights (eg BSD including the source...)

Alan
##SELECTION_END##

[-- Attachment #1.2: Type: text/html, Size: 598 bytes --]

[-- Attachment #2: Type: text/plain, Size: 127 bytes --]

_______________________________________________
Xen-devel mailing list
Xen-devel@lists.xen.org
https://lists.xen.org/xen-devel

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-08-15 20:15         ` Alan Cox
  0 siblings, 0 replies; 176+ messages in thread
From: Alan Cox @ 2016-08-15 20:15 UTC (permalink / raw)
  To: Andy Lutomirski, James Bottomley
  Cc: benh, masami.hiramatsu.pt, linux, linux-kbuild, linux-sh,
	torvalds, akpm, dwmw2, xen-devel, Luis R. Rodriguez,
	anil.s.keshavamurthy, will.deacon, linux-ia64, x86, korea.drzix,
	mingo, andrew.cooper3, jgross, tglx, keescook, ananth, jpoimboe,
	rostedt, hpa, arnd, davem, One Thousand Gnomes,
	platform-driver-x86, jkosina, david.vrabel, realmz6, fontana,
	konrad.wilk, ananth, paul.gortmaker, pali.rohar, ak, pebolle,
	jbaron, mmarek, rusty, tony.luck, catalin.marinas, dvhart,
	linux-arm-kernel, ming.lei, linux, andriy.shevchenko,
	christopher.denicolo, linux-arch, mcb30, heiko.carstens, gregkh,
	mhiramat, ciaran.farrell, bp, sparclinux

[-- Attachment #1: Type: text/plain, Size: 482 bytes --]


> This is the module tag ... it says what licence the module is under,
> not the licence for the module combined with the kernel, which is
> always GPLv2 because the stricter licence rules.

Because if I build a BSD licensed module against the kernel, give you
the binaries and refuse to give you the source I am conforming to the
BSD licence in letter. So to use it with the kernel it needs to be GPL
with additional rights (eg BSD including the source...)

Alan
##SELECTION_END##

[-- Attachment #2: Type: text/html, Size: 598 bytes --]

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
  2016-08-15 20:15         ` Alan Cox
  (?)
@ 2016-08-15 21:00           ` Steven Rostedt
  -1 siblings, 0 replies; 176+ messages in thread
From: Steven Rostedt @ 2016-08-15 21:00 UTC (permalink / raw)
  To: Alan Cox
  Cc: Andy Lutomirski, James Bottomley, benh, masami.hiramatsu.pt,
	linux, linux-kbuild, linux-sh, torvalds, akpm, dwmw2, xen-devel,
	Luis R. Rodriguez, anil.s.keshavamurthy, will.deacon, linux-ia64,
	x86, korea.drzix, mingo, andrew.cooper3, jgross, tglx, keescook,
	ananth, jpoimboe, hpa, arnd, davem, One Thousand Gnomes,
	platform-driver-x86, jkosina, david.vrabel, realmz6, fontana

On Mon, 15 Aug 2016 21:15:06 +0100
Alan Cox <alan@linux.intel.com> wrote:

> > This is the module tag ... it says what licence the module is under,
> > not the licence for the module combined with the kernel, which is
> > always GPLv2 because the stricter licence rules.  
> 
> Because if I build a BSD licensed module against the kernel, give you
> the binaries and refuse to give you the source I am conforming to the
> BSD licence in letter. So to use it with the kernel it needs to be GPL
> with additional rights (eg BSD including the source...)
> 

But that only pertains to the code that was modified to be used with
the Linux kernel, right? That is, if there's a BSD licensed module for
device FOO, and I port it to the Linux kernel, that will need to have a
GPL added to it to be included in Linux. But the original BSD code is
not affected. If a fix is made to the GPL Linux version, I'm assuming
(because I've been asked when doing something like this), that the
author of that fix will have to give it a dual license to be used back
in the original BSD only code. Correct?

I'm just trying to understand this. From what would make sense to me
(but may or may not to a court of law, where it counts), is that the
code added to Linux must be under GPL. But using that code depends on
where you get it from. If you use BSD source, it stays under BSD. But
any fixes to the GPL version will require permission to be put back to
the BSD version. A change to the GPL version doesn't automatically get
allowed back to the BSD only version?

-- Steve

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-08-15 21:00           ` Steven Rostedt
  0 siblings, 0 replies; 176+ messages in thread
From: Steven Rostedt @ 2016-08-15 21:00 UTC (permalink / raw)
  To: Alan Cox
  Cc: Andy Lutomirski, James Bottomley, benh, masami.hiramatsu.pt,
	linux, linux-kbuild, linux-sh, torvalds, akpm, dwmw2, xen-devel,
	Luis R. Rodriguez, anil.s.keshavamurthy, will.deacon, linux-ia64,
	x86, korea.drzix, mingo, andrew.cooper3, jgross, tglx, keescook,
	ananth, jpoimboe, hpa, arnd, davem, One Thousand Gnomes,
	platform-driver-x86, jkosina, david.vrabel, realmz6, fontana

On Mon, 15 Aug 2016 21:15:06 +0100
Alan Cox <alan@linux.intel.com> wrote:

> > This is the module tag ... it says what licence the module is under,
> > not the licence for the module combined with the kernel, which is
> > always GPLv2 because the stricter licence rules.  
> 
> Because if I build a BSD licensed module against the kernel, give you
> the binaries and refuse to give you the source I am conforming to the
> BSD licence in letter. So to use it with the kernel it needs to be GPL
> with additional rights (eg BSD including the source...)
> 

But that only pertains to the code that was modified to be used with
the Linux kernel, right? That is, if there's a BSD licensed module for
device FOO, and I port it to the Linux kernel, that will need to have a
GPL added to it to be included in Linux. But the original BSD code is
not affected. If a fix is made to the GPL Linux version, I'm assuming
(because I've been asked when doing something like this), that the
author of that fix will have to give it a dual license to be used back
in the original BSD only code. Correct?

I'm just trying to understand this. From what would make sense to me
(but may or may not to a court of law, where it counts), is that the
code added to Linux must be under GPL. But using that code depends on
where you get it from. If you use BSD source, it stays under BSD. But
any fixes to the GPL version will require permission to be put back to
the BSD version. A change to the GPL version doesn't automatically get
allowed back to the BSD only version?

-- Steve

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-08-15 21:00           ` Steven Rostedt
  0 siblings, 0 replies; 176+ messages in thread
From: Steven Rostedt @ 2016-08-15 21:00 UTC (permalink / raw)
  To: Alan Cox
  Cc: Andy Lutomirski, James Bottomley, benh, masami.hiramatsu.pt,
	linux, linux-kbuild, linux-sh, torvalds, akpm, dwmw2, xen-devel,
	Luis R. Rodriguez, anil.s.keshavamurthy, will.deacon, linux-ia64,
	x86, korea.drzix, mingo, andrew.cooper3, jgross, tglx, keescook,
	ananth, jpoimboe, hpa, arnd, davem, One Thousand Gnomes,
	platform-driver-x86, jkosina, david.vrabel, realmz6, fontana,
	konrad.wilk, ananth, paul.gortmaker, pali.rohar, ak, pebolle,
	jbaron, mmarek, rusty, tony.luck, catalin.marinas, dvhart,
	linux-arm-kernel, ming.lei, linux, andriy.shevchenko,
	christopher.denicolo, linux-arch, mcb30, heiko.carstens, gregkh,
	mhiramat, ciaran.farrell, bp, sparclinux

On Mon, 15 Aug 2016 21:15:06 +0100
Alan Cox <alan@linux.intel.com> wrote:

> > This is the module tag ... it says what licence the module is under,
> > not the licence for the module combined with the kernel, which is
> > always GPLv2 because the stricter licence rules.  
> 
> Because if I build a BSD licensed module against the kernel, give you
> the binaries and refuse to give you the source I am conforming to the
> BSD licence in letter. So to use it with the kernel it needs to be GPL
> with additional rights (eg BSD including the source...)
> 

But that only pertains to the code that was modified to be used with
the Linux kernel, right? That is, if there's a BSD licensed module for
device FOO, and I port it to the Linux kernel, that will need to have a
GPL added to it to be included in Linux. But the original BSD code is
not affected. If a fix is made to the GPL Linux version, I'm assuming
(because I've been asked when doing something like this), that the
author of that fix will have to give it a dual license to be used back
in the original BSD only code. Correct?

I'm just trying to understand this. From what would make sense to me
(but may or may not to a court of law, where it counts), is that the
code added to Linux must be under GPL. But using that code depends on
where you get it from. If you use BSD source, it stays under BSD. But
any fixes to the GPL version will require permission to be put back to
the BSD version. A change to the GPL version doesn't automatically get
allowed back to the BSD only version?

-- Steve

^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
  2016-08-15 20:15         ` Alan Cox
  (?)
@ 2016-08-15 22:40           ` James Bottomley
  -1 siblings, 0 replies; 176+ messages in thread
From: James Bottomley @ 2016-08-15 22:40 UTC (permalink / raw)
  To: Alan Cox, Andy Lutomirski
  Cc: benh, masami.hiramatsu.pt, linux, linux-kbuild, linux-sh,
	torvalds, akpm, dwmw2, xen-devel, Luis R. Rodriguez,
	anil.s.keshavamurthy, will.deacon, linux-ia64, x86, korea.drzix,
	mingo, andrew.cooper3, jgross, tglx, keescook, ananth, jpoimboe,
	rostedt, hpa, arnd, davem, One Thousand Gnomes,
	platform-driver-x86, jkosina, david.vrabel, realmz6, fontana,
	konrad.wilk, ananth, paul.gortmaker

On Mon, 2016-08-15 at 21:15 +0100, Alan Cox wrote:
> > This is the module tag ... it says what licence the module is 
> > under, not the licence for the module combined with the kernel, 
> > which is always GPLv2 because the stricter licence rules.
> 
> Because if I build a BSD licensed module against the kernel, give you
> the binaries and refuse to give you the source I am conforming to the
> BSD licence in letter.

No, you can't.  Forget dual licensing for a minute: I can produce a
Linux kernel module under a pure BSD licence because BSD is compatible
with GPL.  However, if we assume for the sake of argument that a binary
module is a derived work of Linux, producing and distributing the
binary for the module brings the combination under GPLv2 via the
derivative works clause and I'm required to offer you corresponding
source code in spite of the fact that my module *only* has a BSD
licence.  The only known get out from this is if I make *you* produce
the binary (the open source shim defence).

>  So to use it with the kernel it needs to be GPL with additional
> rights (eg BSD including the source...)

I'm not quite sure what you're disagreeing over?  Is it semantics of a
Dual BSD/GPL licence vs a GPL with additional rights one?  Dual
licensed code is a well settled area: the ruling licence is the one
which permits the action.  So for a dual licencesed kernel module, if I
compile the module as a binary and distribute it, I'm required to
follow all the provisions of GPLv2 i.e. make you and offer of
corresponding source.   Conversely, if I cut and paste a section of the
driver source code into a BSD driver, I'm permitted to do this under
the BSD licence, so the pasted code doesn't carry GPLv2 contamination
into BSD.

You can certainly call the Dual BSD/GPL licence a GPL licence with
additional permission to include the source code in a BSD licensed
system, but it's not a precise equivalence because a true Dual Licensed
BSD/GPL driver may be cut and pasted into any code which is compatible
either with the BSD or GPL licences, meaning it's actually less strict
than your additional permission to include into BSD.

James


^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-08-15 22:40           ` James Bottomley
  0 siblings, 0 replies; 176+ messages in thread
From: James Bottomley @ 2016-08-15 22:40 UTC (permalink / raw)
  To: Alan Cox, Andy Lutomirski
  Cc: benh, masami.hiramatsu.pt, linux, linux-kbuild, linux-sh,
	torvalds, akpm, dwmw2, xen-devel, Luis R. Rodriguez,
	anil.s.keshavamurthy, will.deacon, linux-ia64, x86, korea.drzix,
	mingo, andrew.cooper3, jgross, tglx, keescook, ananth, jpoimboe,
	rostedt, hpa, arnd, davem, One Thousand Gnomes,
	platform-driver-x86, jkosina, david.vrabel, realmz6, fontana,
	konrad.wilk, ananth, paul.gortmaker

On Mon, 2016-08-15 at 21:15 +0100, Alan Cox wrote:
> > This is the module tag ... it says what licence the module is 
> > under, not the licence for the module combined with the kernel, 
> > which is always GPLv2 because the stricter licence rules.
> 
> Because if I build a BSD licensed module against the kernel, give you
> the binaries and refuse to give you the source I am conforming to the
> BSD licence in letter.

No, you can't.  Forget dual licensing for a minute: I can produce a
Linux kernel module under a pure BSD licence because BSD is compatible
with GPL.  However, if we assume for the sake of argument that a binary
module is a derived work of Linux, producing and distributing the
binary for the module brings the combination under GPLv2 via the
derivative works clause and I'm required to offer you corresponding
source code in spite of the fact that my module *only* has a BSD
licence.  The only known get out from this is if I make *you* produce
the binary (the open source shim defence).

>  So to use it with the kernel it needs to be GPL with additional
> rights (eg BSD including the source...)

I'm not quite sure what you're disagreeing over?  Is it semantics of a
Dual BSD/GPL licence vs a GPL with additional rights one?  Dual
licensed code is a well settled area: the ruling licence is the one
which permits the action.  So for a dual licencesed kernel module, if I
compile the module as a binary and distribute it, I'm required to
follow all the provisions of GPLv2 i.e. make you and offer of
corresponding source.   Conversely, if I cut and paste a section of the
driver source code into a BSD driver, I'm permitted to do this under
the BSD licence, so the pasted code doesn't carry GPLv2 contamination
into BSD.

You can certainly call the Dual BSD/GPL licence a GPL licence with
additional permission to include the source code in a BSD licensed
system, but it's not a precise equivalence because a true Dual Licensed
BSD/GPL driver may be cut and pasted into any code which is compatible
either with the BSD or GPL licences, meaning it's actually less strict
than your additional permission to include into BSD.

James


^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-08-15 22:40           ` James Bottomley
  0 siblings, 0 replies; 176+ messages in thread
From: James Bottomley @ 2016-08-15 22:40 UTC (permalink / raw)
  To: Alan Cox, Andy Lutomirski
  Cc: benh, masami.hiramatsu.pt, linux, linux-kbuild, linux-sh,
	torvalds, akpm, dwmw2, xen-devel, Luis R. Rodriguez,
	anil.s.keshavamurthy, will.deacon, linux-ia64, x86, korea.drzix,
	mingo, andrew.cooper3, jgross, tglx, keescook, ananth, jpoimboe,
	rostedt, hpa, arnd, davem, One Thousand Gnomes,
	platform-driver-x86, jkosina, david.vrabel, realmz6, fontana,
	konrad.wilk, ananth, paul.gortmaker, pali.rohar, ak, pebolle,
	jbaron, mmarek, rusty, tony.luck, catalin.marinas, dvhart,
	linux-arm-kernel, ming.lei, linux, andriy.shevchenko,
	christopher.denicolo, linux-arch, mcb30, heiko.carstens, gregkh,
	mhiramat, ciaran.farrell, bp, sparclinux

On Mon, 2016-08-15 at 21:15 +0100, Alan Cox wrote:
> > This is the module tag ... it says what licence the module is 
> > under, not the licence for the module combined with the kernel, 
> > which is always GPLv2 because the stricter licence rules.
> 
> Because if I build a BSD licensed module against the kernel, give you
> the binaries and refuse to give you the source I am conforming to the
> BSD licence in letter.

No, you can't.  Forget dual licensing for a minute: I can produce a
Linux kernel module under a pure BSD licence because BSD is compatible
with GPL.  However, if we assume for the sake of argument that a binary
module is a derived work of Linux, producing and distributing the
binary for the module brings the combination under GPLv2 via the
derivative works clause and I'm required to offer you corresponding
source code in spite of the fact that my module *only* has a BSD
licence.  The only known get out from this is if I make *you* produce
the binary (the open source shim defence).

>  So to use it with the kernel it needs to be GPL with additional
> rights (eg BSD including the source...)

I'm not quite sure what you're disagreeing over?  Is it semantics of a
Dual BSD/GPL licence vs a GPL with additional rights one?  Dual
licensed code is a well settled area: the ruling licence is the one
which permits the action.  So for a dual licencesed kernel module, if I
compile the module as a binary and distribute it, I'm required to
follow all the provisions of GPLv2 i.e. make you and offer of
corresponding source.   Conversely, if I cut and paste a section of the
driver source code into a BSD driver, I'm permitted to do this under
the BSD licence, so the pasted code doesn't carry GPLv2 contamination
into BSD.

You can certainly call the Dual BSD/GPL licence a GPL licence with
additional permission to include the source code in a BSD licensed
system, but it's not a precise equivalence because a true Dual Licensed
BSD/GPL driver may be cut and pasted into any code which is compatible
either with the BSD or GPL licences, meaning it's actually less strict
than your additional permission to include into BSD.

James


^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
  2016-08-10  4:51       ` Andy Lutomirski
  (?)
@ 2016-08-15 22:44         ` James Bottomley
  -1 siblings, 0 replies; 176+ messages in thread
From: James Bottomley @ 2016-08-15 22:44 UTC (permalink / raw)
  To: Andy Lutomirski
  Cc: benh, masami.hiramatsu.pt, linux, linux-kbuild, linux-sh,
	torvalds, akpm, dwmw2, xen-devel, Luis R. Rodriguez,
	anil.s.keshavamurthy, will.deacon, linux-ia64, x86, korea.drzix,
	mingo, andrew.cooper3, jgross, tglx, keescook, ananth, jpoimboe,
	rostedt, hpa, arnd, davem, One Thousand Gnomes,
	platform-driver-x86, jkosina, david.vrabel, realmz6, fontana,
	konrad.wilk, ananth, paul.gortmaker

On Tue, 2016-08-09 at 21:51 -0700, Andy Lutomirski wrote:
> On Aug 9, 2016 7:09 PM, "James Bottomley" <
> James.Bottomley@hansenpartnership.com> wrote:
> > 
> > On Tue, 2016-08-09 at 15:24 +0100, One Thousand Gnomes wrote:
> > > > table development go under copyleft-next, Rusty recently asked 
> > > > for code to go in prior to the license tag being added denoting
> > > > this license as GPL-compatible [3] -- I had noted in the patch
> > > > submission which annotated copyleft-next's compatibility to 
> > > > GPLv2 that copyleft-next is the license of choice for ongoing 
> > > > kernel development on my end [4]. If this is objectionable I'm 
> > > > happy to change it to GPLv2 however I'd like a reason provided 
> > > > as I've gone through all possible channels to ensure this is 
> > > > kosher, including vetting by 3 attorneys now, 2 at SUSE.
> > > 
> > > You don't need a new tag, you can use "GPL" or "GPL and 
> > > additional rights". In fact you don't want any other tag because 
> > > when combined  with the kernel it is GPLv2 anyway because the 
> > > only way the two are fully compatible is for the kernel community 
> > > to license the derived work under the GPL.
> > 
> > This is the module tag ... it says what licence the module is 
> > under, not the licence for the module combined with the kernel, 
> > which is always GPLv2 because the stricter licence rules.
> 
> Then why isn't "BSD" in the license_is_gpl_compatible list?

[Sorry about this, the list seems to have stopped sending me copies of
stuff I'm on the to: line for; not sure why.  Anyway, having fished
this copy out of my trash:]

It is, here specifically:

https://www.gnu.org/licenses/license-list.en.html#ModifiedBSD

James


^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-08-15 22:44         ` James Bottomley
  0 siblings, 0 replies; 176+ messages in thread
From: James Bottomley @ 2016-08-15 22:44 UTC (permalink / raw)
  To: Andy Lutomirski
  Cc: benh, masami.hiramatsu.pt, linux, linux-kbuild, linux-sh,
	torvalds, akpm, dwmw2, xen-devel, Luis R. Rodriguez,
	anil.s.keshavamurthy, will.deacon, linux-ia64, x86, korea.drzix,
	mingo, andrew.cooper3, jgross, tglx, keescook, ananth, jpoimboe,
	rostedt, hpa, arnd, davem, One Thousand Gnomes,
	platform-driver-x86, jkosina, david.vrabel, realmz6, fontana,
	konrad.wilk, ananth, paul.gortmaker

On Tue, 2016-08-09 at 21:51 -0700, Andy Lutomirski wrote:
> On Aug 9, 2016 7:09 PM, "James Bottomley" <
> James.Bottomley@hansenpartnership.com> wrote:
> > 
> > On Tue, 2016-08-09 at 15:24 +0100, One Thousand Gnomes wrote:
> > > > table development go under copyleft-next, Rusty recently asked 
> > > > for code to go in prior to the license tag being added denoting
> > > > this license as GPL-compatible [3] -- I had noted in the patch
> > > > submission which annotated copyleft-next's compatibility to 
> > > > GPLv2 that copyleft-next is the license of choice for ongoing 
> > > > kernel development on my end [4]. If this is objectionable I'm 
> > > > happy to change it to GPLv2 however I'd like a reason provided 
> > > > as I've gone through all possible channels to ensure this is 
> > > > kosher, including vetting by 3 attorneys now, 2 at SUSE.
> > > 
> > > You don't need a new tag, you can use "GPL" or "GPL and 
> > > additional rights". In fact you don't want any other tag because 
> > > when combined  with the kernel it is GPLv2 anyway because the 
> > > only way the two are fully compatible is for the kernel community 
> > > to license the derived work under the GPL.
> > 
> > This is the module tag ... it says what licence the module is 
> > under, not the licence for the module combined with the kernel, 
> > which is always GPLv2 because the stricter licence rules.
> 
> Then why isn't "BSD" in the license_is_gpl_compatible list?

[Sorry about this, the list seems to have stopped sending me copies of
stuff I'm on the to: line for; not sure why.  Anyway, having fished
this copy out of my trash:]

It is, here specifically:

https://www.gnu.org/licenses/license-list.en.html#ModifiedBSD

James


^ permalink raw reply	[flat|nested] 176+ messages in thread

* Re: [RFC v3 00/13] linux: generalize sections, ranges and linker tables
@ 2016-08-15 22:44         ` James Bottomley
  0 siblings, 0 replies; 176+ messages in thread
From: James Bottomley @ 2016-08-15 22:44 UTC (permalink / raw)
  To: Andy Lutomirski
  Cc: benh, masami.hiramatsu.pt, linux, linux-kbuild, linux-sh,
	torvalds, akpm, dwmw2, xen-devel, Luis R. Rodriguez,
	anil.s.keshavamurthy, will.deacon, linux-ia64, x86, korea.drzix,
	mingo, andrew.cooper3, jgross, tglx, keescook, ananth, jpoimboe,
	rostedt, hpa, arnd, davem, One Thousand Gnomes,
	platform-driver-x86, jkosina, david.vrabel, realmz6, fontana,
	konrad.wilk, ananth, paul.gortmaker, pali.rohar, ak, pebolle,
	jbaron, mmarek, rusty, tony.luck, catalin.marinas, dvhart,
	linux-arm-kernel, ming.lei, linux, andriy.shevchenko,
	christopher.denicolo, linux-arch, mcb30, heiko.carstens, gregkh,
	mhiramat, ciaran.farrell, bp, sparclinux, alan

On Tue, 2016-08-09 at 21:51 -0700, Andy Lutomirski wrote:
> On Aug 9, 2016 7:09 PM, "James Bottomley" <
> James.Bottomley@hansenpartnership.com> wrote:
> > 
> > On Tue, 2016-08-09 at 15:24 +0100, One Thousand Gnomes wrote:
> > > > table development go under copyleft-next, Rusty recently asked 
> > > > for code to go in prior to the license tag being added denoting
> > > > this license as GPL-compatible [3] -- I had noted in the patch
> > > > submission which annotated copyleft-next's compatibility to 
> > > > GPLv2 that copyleft-next is the license of choice for ongoing 
> > > > kernel development on my end [4]. If this is objectionable I'm 
> > > > happy to change it to GPLv2 however I'd like a reason provided 
> > > > as I've gone through all possible channels to ensure this is 
> > > > kosher, including vetting by 3 attorneys now, 2 at SUSE.
> > > 
> > > You don't need a new tag, you can use "GPL" or "GPL and 
> > > additional rights". In fact you don't want any other tag because 
> > > when combined  with the kernel it is GPLv2 anyway because the 
> > > only way the two are fully compatible is for the kernel community 
> > > to license the derived work under the GPL.
> > 
> > This is the module tag ... it says what licence the module is 
> > under, not the licence for the module combined with the kernel, 
> > which is always GPLv2 because the stricter licence rules.
> 
> Then why isn't "BSD" in the license_is_gpl_compatible list?

[Sorry about this, the list seems to have stopped sending me copies of
stuff I'm on the to: line for; not sure why.  Anyway, having fished
this copy out of my trash:]

It is, here specifically:

https://www.gnu.org/licenses/license-list.en.html#ModifiedBSD

James


^ permalink raw reply	[flat|nested] 176+ messages in thread

end of thread, other threads:[~2016-08-15 22:44 UTC | newest]

Thread overview: 176+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-07-22 21:24 [RFC v3 00/13] linux: generalize sections, ranges and linker tables Luis R. Rodriguez
2016-07-22 21:24 ` Luis R. Rodriguez
2016-07-22 21:24 ` Luis R. Rodriguez
2016-07-22 21:24 ` [RFC v3 01/13] x86: remove LTO_REFERENCE_INITCALL() Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:24 ` [RFC v3 02/13] dell-smo8800: include uaccess.h Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:31   ` Pali Rohár
2016-07-22 21:31     ` Pali Rohár
2016-07-22 21:31     ` Pali Rohár
2016-07-22 21:24 ` [RFC v3 03/13] scripts/module-common.lds: enable generation Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:24 ` [RFC v3 04/13] sections.h: guard against asm and linker script Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:24 ` [RFC v3 05/13] sections.h: add sections header to collect all section info Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:37   ` James Hogan
2016-07-22 21:37     ` James Hogan
2016-07-22 21:37     ` James Hogan
2016-07-22 21:41     ` Luis R. Rodriguez
2016-07-22 21:41       ` Luis R. Rodriguez
2016-07-22 21:41       ` Luis R. Rodriguez
2016-07-29 17:28     ` Steven Rostedt
2016-07-29 17:28       ` Steven Rostedt
2016-07-29 17:28       ` Steven Rostedt
2016-07-22 21:24 ` [RFC v3 06/13] ranges.h: add helpers to build and identify Linux section ranges Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:24 ` [RFC v3 07/13] tables.h: add linker table support Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-25 15:30   ` Masami Hiramatsu
2016-07-25 15:30     ` Masami Hiramatsu
2016-07-25 15:30     ` Masami Hiramatsu
2016-07-27 23:02     ` Luis R. Rodriguez
2016-07-27 23:02       ` Luis R. Rodriguez
2016-07-27 23:02       ` Luis R. Rodriguez
2016-07-28 17:08       ` H. Peter Anvin
2016-07-28 17:08       ` H. Peter Anvin
2016-07-28 17:08       ` H. Peter Anvin
2016-07-28 17:08         ` H. Peter Anvin
2016-07-28 17:08       ` H. Peter Anvin
2016-07-29 10:06   ` Borislav Petkov
2016-07-29 10:06     ` Borislav Petkov
2016-07-29 10:06     ` Borislav Petkov
2016-08-08 15:05     ` Luis R. Rodriguez
2016-08-08 15:05       ` Luis R. Rodriguez
2016-08-08 15:05       ` Luis R. Rodriguez
2016-08-09  3:55       ` Borislav Petkov
2016-08-09  3:55         ` Borislav Petkov
2016-08-09  3:55         ` Borislav Petkov
2016-08-12  3:51         ` Luis R. Rodriguez
2016-08-12  3:51           ` Luis R. Rodriguez
2016-08-12  3:51           ` Luis R. Rodriguez
2016-08-12  5:23           ` Borislav Petkov
2016-08-12  5:23             ` Borislav Petkov
2016-08-12  5:23             ` Borislav Petkov
2016-08-12  6:50             ` Luis R. Rodriguez
2016-08-12  6:50               ` Luis R. Rodriguez
2016-08-12  6:50               ` Luis R. Rodriguez
2016-08-12  7:25               ` Borislav Petkov
2016-08-12  7:25                 ` Borislav Petkov
2016-08-12  7:25                 ` Borislav Petkov
2016-08-12 15:28                 ` Luis R. Rodriguez
2016-08-12 15:28                   ` Luis R. Rodriguez
2016-08-12 15:28                   ` Luis R. Rodriguez
2016-08-12 15:51                   ` Borislav Petkov
2016-08-12 15:51                     ` Borislav Petkov
2016-08-12 15:51                     ` Borislav Petkov
2016-08-12 17:04                     ` Luis R. Rodriguez
2016-08-12 17:04                       ` Luis R. Rodriguez
2016-08-12 17:04                       ` Luis R. Rodriguez
2016-08-12 17:35                       ` Borislav Petkov
2016-08-12 17:35                         ` Borislav Petkov
2016-08-12 17:35                         ` Borislav Petkov
2016-08-12 18:16                         ` Kees Cook
2016-08-12 20:23                       ` Greg KH
2016-08-12 20:23                         ` Greg KH
2016-08-12 20:23                         ` Greg KH
2016-08-12 20:46                         ` Jiri Kosina
2016-08-12 20:46                           ` Jiri Kosina
2016-08-12 20:46                           ` Jiri Kosina
2016-08-12 22:00                         ` Luis R. Rodriguez
2016-08-12 22:00                           ` Luis R. Rodriguez
2016-08-12 22:00                           ` Luis R. Rodriguez
2016-08-13 10:46                           ` Greg KH
2016-08-13 10:46                             ` Greg KH
2016-08-13 10:46                             ` Greg KH
2016-08-13 17:54                             ` Luis R. Rodriguez
2016-08-13 17:54                               ` Luis R. Rodriguez
2016-08-13 17:54                               ` Luis R. Rodriguez
2016-07-22 21:24 ` [RFC v3 08/13] firmware/Makefile: force recompilation if makefile changes Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:24 ` [RFC v3 09/13] firmware: port built-in section to linker table Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:24 ` [RFC v3 10/13] jump_label: port __jump_table to linker tables Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:49   ` Josh Poimboeuf
2016-07-22 21:49     ` Josh Poimboeuf
2016-07-22 21:49     ` Josh Poimboeuf
2016-07-22 22:26     ` Luis R. Rodriguez
2016-07-22 22:26       ` Luis R. Rodriguez
2016-07-22 22:26       ` Luis R. Rodriguez
2016-07-22 22:55       ` Josh Poimboeuf
2016-07-22 22:55         ` Josh Poimboeuf
2016-07-22 22:55         ` Josh Poimboeuf
2016-07-27 22:55         ` Luis R. Rodriguez
2016-07-27 22:55           ` Luis R. Rodriguez
2016-07-27 22:55           ` Luis R. Rodriguez
2016-07-22 21:24 ` [RFC v3 11/13] dynamic_debug: port to use " Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:24 ` [RFC v3 12/13] kprobes: port .kprobes.text to section range Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-25 15:19   ` Masami Hiramatsu
2016-07-25 15:19     ` Masami Hiramatsu
2016-07-25 15:19     ` Masami Hiramatsu
2016-07-27 22:40     ` Luis R. Rodriguez
2016-07-27 22:40       ` Luis R. Rodriguez
2016-07-27 22:40       ` Luis R. Rodriguez
2016-07-22 21:24 ` [RFC v3 13/13] kprobes: port blacklist kprobes to linker table Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-22 21:24   ` Luis R. Rodriguez
2016-07-25 15:27   ` Masami Hiramatsu
2016-07-25 15:27     ` Masami Hiramatsu
2016-07-25 15:27     ` Masami Hiramatsu
2016-07-27 23:00     ` Luis R. Rodriguez
2016-07-27 23:00       ` Luis R. Rodriguez
2016-07-27 23:00       ` Luis R. Rodriguez
2016-07-25 13:32 ` [RFC v3 00/13] linux: generalize sections, ranges and linker tables Masami Hiramatsu
2016-07-25 13:32   ` Masami Hiramatsu
2016-07-25 13:32   ` Masami Hiramatsu
2016-07-25 13:55   ` Richard Fontana
2016-07-25 13:55     ` Richard Fontana
2016-07-25 13:55     ` Richard Fontana
2016-07-27 22:46   ` Luis R. Rodriguez
2016-07-27 22:46     ` Luis R. Rodriguez
2016-07-27 22:46     ` Luis R. Rodriguez
2016-07-27 22:27 ` Luis R. Rodriguez
2016-08-09 14:24 ` One Thousand Gnomes
2016-08-09 14:24   ` One Thousand Gnomes
2016-08-09 14:24   ` One Thousand Gnomes
2016-08-09 16:09   ` James Bottomley
2016-08-09 16:09     ` James Bottomley
2016-08-09 16:09     ` James Bottomley
2016-08-10  4:51     ` Andy Lutomirski
2016-08-10  4:51       ` Andy Lutomirski
2016-08-15 20:15       ` Alan Cox
2016-08-15 20:15         ` Alan Cox
2016-08-15 21:00         ` Steven Rostedt
2016-08-15 21:00           ` Steven Rostedt
2016-08-15 21:00           ` Steven Rostedt
2016-08-15 22:40         ` James Bottomley
2016-08-15 22:40           ` James Bottomley
2016-08-15 22:40           ` James Bottomley
2016-08-15 22:44       ` James Bottomley
2016-08-15 22:44         ` James Bottomley
2016-08-15 22:44         ` James Bottomley
2016-08-10 17:03     ` Luis R. Rodriguez
2016-08-10 17:03       ` Luis R. Rodriguez
2016-08-10 17:03       ` Luis R. Rodriguez
2016-08-09 16:48   ` Richard Fontana
2016-08-09 16:48     ` Richard Fontana
2016-08-09 16:48     ` Richard Fontana
2016-08-09 16:52   ` Richard Fontana
2016-08-09 16:52     ` Richard Fontana
2016-08-09 16:52     ` Richard Fontana

This is an external index of several public inboxes,
see mirroring instructions on how to clone and mirror
all data and code used by this external index.