Skip to contentSkip to conversation

linux: generalize sections, ranges and linker tables

PATCH Superseded [email protected] 16 participants 158 messages Aug 19, 2016 – Feb 1, 2017 Page 3 of 3

Subsystems (32)
lore
Share & tools
lore
author maintainer
#135 lore raw

PATCH v7 1/14 generic-sections: add section core helpers

In reply to Luis R. Rodriguez

Linux makes extensive use of custom ELF header sections, documentation for these are well scattered. Unify this documentation in a central place and provide helpers to build custom Linux sections.

This also generalizes sections code to enable avoiding modifying the linker scripts when we want to add new custom Linux sections. In order to make this generally useful we need to ensure all architectures can make use of core section helpers but that they can also override should this be needed. Instead of relying on section.h this adds a sections-core.h since this will be targeted to be safe to be used on asm code, linker scripts and C code.

v7: ran ispell to fix spelling as requested by Boris

v5:

o Huge documentation revamp based on a careful review of the ELF specifications. Includes documentation now also about usage of two dots (..) when prefixing ELF program specific sections.

o Replace macros for sections names in favor of just using the section names explicitly in the linker script. This is perhaps more work to grep but this is what folks seem to currently prefer.

o Fix .text and .rodata documentation to explain memory protection strategies which architectures can embrace upon initialization (documents CONFIG_DEBUG_RODATA and mark_rodata_ro())

o Skip the 'Linux section ordering' documentation section, we'll instead add this on subsequent patch which will expand on it considerably

o Dropped tree on MAINTAINERS -- as per discussions with Arnd, hpa and Josh, its easier to just let changes for sections go in through the respective tree that needs the changes.

o Fix typos on documentation

o Dropped SECTION_ALL(), __SECTION_CORE(), SECTION_CORE_ALL() macros since we are favoring using explicit section names. These are useless if we are being explicit.

o Drop LINUX_SECTION_SIZE(), LINUX_SECTION_EMPTY() in favor of having section ranges and linker tables define their own, to avoid confusion and make code more readable.

o Add __define_initcall() documentation and a small section describing our current initcall levels. This should help also clarify what was meant about keeping backward compatibility.

v4:

o Port to shiny new sphinx documentation format

o fix a unicore32 build, turns out this actually fixes unicore32 defconfig builds which were failing for a long while. unicore32 does not seem to grok well the type passed on a section declaration, this ignores it.

o Use VMLINUX_SYMBOL() in more user symbols (extern C code), not doing this was causing final linker issues with blackfin -- this is a CONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX=y architecture. The other one being metatag. metatag is not supported on 0-day so I cannot confirm compilation there.

o Added SECTION_CORE() for C code, used later by __LINUX_RANGE()

o Since SECTION_CORE() is defined for linker script and C code, share the same helper and just use a __stringify() for the C code as is done for the other C helpers.

o move generic sections to asm-generic/section-core.h instead. PowerPC compilation blows up if asm/jump_labels.h gets section.h included, fixing this is not in any way easy. The list of issues are endless. Moving new data to a new simple file resolves this.

o since things are now in asm-generic/section-core.h the guard changes on asm-generic/sections.h and each architecture sections.h are no longer needed

o Give generic sections some maintainer love, that change is Acked-by Arnd Bergmann, Josh and hpa.

o A few checkpatch.pl style fixes

o As suggested by James Hogan use generic-y to copy generic header files on architectures that do not have a sections.h instead of writing a simple file only to include the generic one.

v3:

o add missing sections.h for architectures that did not have it

o move generic sections to asm-generic/sections.h

o add generic asm helpers section_type(), section_type_asmtype(), push_section_type() -- these helpers enable easy use for for later declaring and using of custom Linux sections using more standard APIs in both C code, asm code (C asm calls, or asm files), enabling future standardized section types to be more immediately accessible to asm code, not just C code. Note for ASM_CMD_SEP we use by default "\n", architectures needed to override can do so on their own sections.h prior to inclusion of asm-generic/sections.h

---
 Documentation/index.rst                   |   1 +
 Documentation/sections/background.rst     | 105 ++++++++++
 Documentation/sections/conf.py            |   4 +
 Documentation/sections/index.rst          |  17 ++
 Documentation/sections/section-core.rst   | 148 ++++++++++++++
 MAINTAINERS                               |  12 ++
 arch/alpha/include/asm/Kbuild             |   1 +
 arch/arc/include/asm/Kbuild               |   1 +
 arch/arm/include/asm/Kbuild               |   1 +
 arch/arm64/include/asm/Kbuild             |   1 +
 arch/avr32/include/asm/Kbuild             |   1 +
 arch/blackfin/include/asm/Kbuild          |   1 +
 arch/c6x/include/asm/Kbuild               |   1 +
 arch/cris/include/asm/Kbuild              |   1 +
 arch/frv/include/asm/Kbuild               |   1 +
 arch/h8300/include/asm/Kbuild             |   1 +
 arch/hexagon/include/asm/Kbuild           |   1 +
 arch/ia64/include/asm/Kbuild              |   1 +
 arch/m32r/include/asm/Kbuild              |   1 +
 arch/m68k/include/asm/Kbuild              |   1 +
 arch/metag/include/asm/Kbuild             |   1 +
 arch/microblaze/include/asm/Kbuild        |   1 +
 arch/mips/include/asm/Kbuild              |   1 +
 arch/mn10300/include/asm/Kbuild           |   1 +
 arch/nios2/include/asm/Kbuild             |   1 +
 arch/openrisc/include/asm/Kbuild          |   1 +
 arch/parisc/include/asm/Kbuild            |   1 +
 arch/powerpc/include/asm/Kbuild           |   1 +
 arch/s390/include/asm/Kbuild              |   1 +
 arch/score/include/asm/Kbuild             |   1 +
 arch/sh/include/asm/Kbuild                |   1 +
 arch/sparc/include/asm/Kbuild             |   1 +
 arch/tile/include/asm/Kbuild              |   1 +
 arch/um/include/asm/Kbuild                |   1 +
 arch/unicore32/include/asm/section-core.h |  19 ++
 arch/x86/include/asm/Kbuild               |   1 +
 arch/xtensa/include/asm/Kbuild            |   1 +
 include/asm-generic/section-core.h        | 307 ++++++++++++++++++++++++++++++
 include/asm-generic/sections.h            |   2 +
 include/asm-generic/vmlinux.lds.h         |   1 +
 include/linux/init.h                      |  89 +++++++--
 include/linux/sections.h                  |  87 +++++++++
 42 files changed, 809 insertions(+), 13 deletions(-)
 create mode 100644 Documentation/sections/background.rst
 create mode 100644 Documentation/sections/conf.py
 create mode 100644 Documentation/sections/index.rst
 create mode 100644 Documentation/sections/section-core.rst
 create mode 100644 arch/unicore32/include/asm/section-core.h
 create mode 100644 include/asm-generic/section-core.h
 create mode 100644 include/linux/sections.h
Documentation/index.rst +1 -0
index cb5d77699c60..71e0305c036d 100644
@@ -57,6 +57,7 @@ needed).
    media/index
    gpu/index
    security/index
+   sections/index
    sound/index
    crypto/index
 
Documentation/sections/background.rst new file +105 -0

105 lines not on this page · raw message

Documentation/sections/conf.py new file +4 -0
new file mode 100644
index 000000000000..faa1c57595e1
@@ -0,0 +1,4 @@
+# -*- coding: utf-8; mode: python -*-
+
+project = 'Linux Kernel ELF sections'
+html_search_language = 'en'
Documentation/sections/index.rst new file +17 -0
new file mode 100644
index 000000000000..f37511ef05e7
@@ -0,0 +1,17 @@
+=========================
+Linux Kernel ELF sections
+=========================
+
+This book documents the different ELF sections used on the Linux kernel.
+We start off by providing references to how ELF was standardized, references
+to the standards on ELF sections, review limitations of ELF sections, and
+finally how Linux uses ELF sections in the Linux kernel. Certain important
+Linux ELF sections are documented carefully: we describe the goal of the
+ELF section, and address concurrency considerations when applicable. A few
+common a set of Linux helpers for ELF sections are also documented.
+
+.. toctree::
+   :maxdepth: 4
+
+   background
+   section-core
Documentation/sections/section-core.rst new file +148 -0

148 lines not on this page · raw message

MAINTAINERS +12 -0
index d2db7fecef32..5e580b1257fb 100644
@@ -5438,6 +5438,18 @@ S:	Supported
 F:	drivers/base/power/domain*.c
 F:	include/linux/pm_domain.h
 
+GENERIC SECTIONS
+M:	"Luis R. Rodriguez" <[email protected]>
+M:	Josh Poimboeuf <[email protected]>
+M:	"H. Peter Anvin" <[email protected]>
+L:	[email protected]
+L:	[email protected]
+S:	Supported
+F:	include/asm-generic/section-core.h
+F:	include/asm-generic/sections.h
+F:	include/asm-generic/vmlinux.lds.h
+F:	Documentation/sections/section-core.rst
+
 GENERIC UIO DRIVER FOR PCI DEVICES
 M:	"Michael S. Tsirkin" <[email protected]>
 L:	[email protected]
arch/alpha/include/asm/Kbuild +1 -0
index bf8475ce85ee..5422827f1585 100644
@@ -10,3 +10,4 @@ generic-y += mm-arch-hooks.h
 generic-y += preempt.h
 generic-y += sections.h
 generic-y += trace_clock.h
+generic-y += section-core.h
arch/arc/include/asm/Kbuild +1 -0
index c332604606dd..7b2cb3dea5fc 100644
@@ -51,3 +51,4 @@ generic-y += user.h
 generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
+generic-y += section-core.h
arch/arm/include/asm/Kbuild +1 -0
index efb21757d41f..9b69a22a9ae1 100644
@@ -41,3 +41,4 @@ generic-y += unaligned.h
 
 generated-y += mach-types.h
 generated-y += unistd-nr.h
+generic-y += section-core.h
arch/arm64/include/asm/Kbuild +1 -0
index 8365a84c2640..00ace5e826f1 100644
@@ -45,3 +45,4 @@ generic-y += unaligned.h
 generic-y += user.h
 generic-y += vga.h
 generic-y += xor.h
+generic-y += section-core.h
arch/avr32/include/asm/Kbuild +1 -0
index 241b9b9729d8..f2c3b656a0e7 100644
@@ -22,3 +22,4 @@ generic-y += trace_clock.h
 generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
+generic-y += section-core.h
arch/blackfin/include/asm/Kbuild +1 -0
index 2fb67b59d188..bf20541bcf21 100644
@@ -47,3 +47,4 @@ generic-y += unaligned.h
 generic-y += user.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
+generic-y += section-core.h
arch/c6x/include/asm/Kbuild +1 -0
index 64465e7e2245..38127ce747be 100644
@@ -62,3 +62,4 @@ generic-y += user.h
 generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
+generic-y += section-core.h
arch/cris/include/asm/Kbuild +1 -0
index 1778805f6380..385cd88a9d9e 100644
@@ -45,3 +45,4 @@ generic-y += types.h
 generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
+generic-y += section-core.h
arch/frv/include/asm/Kbuild +1 -0
index 1fa084cf1a43..46d7c599d9b8 100644
@@ -8,3 +8,4 @@ generic-y += mm-arch-hooks.h
 generic-y += preempt.h
 generic-y += trace_clock.h
 generic-y += word-at-a-time.h
+generic-y += section-core.h
arch/h8300/include/asm/Kbuild +1 -0
index 373cb23301e3..1ec04ec1c82b 100644
@@ -75,3 +75,4 @@ generic-y += unaligned.h
 generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
+generic-y += section-core.h
arch/hexagon/include/asm/Kbuild +1 -0
index db8ddabc6bd2..37d7bfae7619 100644
@@ -60,3 +60,4 @@ generic-y += unaligned.h
 generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
+generic-y += section-core.h
arch/ia64/include/asm/Kbuild +1 -0
index 502a91d8dbbd..672c6d5da18c 100644
@@ -9,3 +9,4 @@ generic-y += preempt.h
 generic-y += trace_clock.h
 generic-y += vtime.h
 generic-y += word-at-a-time.h
+generic-y += section-core.h
arch/m32r/include/asm/Kbuild +1 -0
index 6e69d2c42eee..8ccfb5eb9678 100644
@@ -12,3 +12,4 @@ generic-y += preempt.h
 generic-y += sections.h
 generic-y += trace_clock.h
 generic-y += word-at-a-time.h
+generic-y += section-core.h
arch/m68k/include/asm/Kbuild +1 -0
index 1f2e5d31cb24..1277b45bf4f9 100644
@@ -34,3 +34,4 @@ generic-y += trace_clock.h
 generic-y += types.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
+generic-y += section-core.h
arch/metag/include/asm/Kbuild +1 -0
index 167150c701d1..b1011375cd7a 100644
@@ -55,3 +55,4 @@ generic-y += user.h
 generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
+generic-y += section-core.h
arch/microblaze/include/asm/Kbuild +1 -0
index b0ae88c9fed9..c6c2cf6edc98 100644
@@ -11,3 +11,4 @@ generic-y += preempt.h
 generic-y += syscalls.h
 generic-y += trace_clock.h
 generic-y += word-at-a-time.h
+generic-y += section-core.h
arch/mips/include/asm/Kbuild +1 -0
index ed07179fe26a..7a932b4a5531 100644
@@ -21,3 +21,4 @@ generic-y += unaligned.h
 generic-y += user.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
+generic-y += section-core.h
arch/mn10300/include/asm/Kbuild +1 -0
index 1c8dd0f5cd5d..f8145bc85835 100644
@@ -10,3 +10,4 @@ generic-y += preempt.h
 generic-y += sections.h
 generic-y += trace_clock.h
 generic-y += word-at-a-time.h
+generic-y += section-core.h
arch/nios2/include/asm/Kbuild +1 -0
index d63330e88379..c9c7cb82b00f 100644
@@ -63,3 +63,4 @@ generic-y += user.h
 generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
+generic-y += section-core.h
arch/openrisc/include/asm/Kbuild +1 -0
index 2832f031fb11..86175e701869 100644
@@ -71,3 +71,4 @@ generic-y += user.h
 generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
+generic-y += section-core.h
arch/parisc/include/asm/Kbuild +1 -0
index 91f53c07f410..18a9d4c5ead7 100644
@@ -28,3 +28,4 @@ generic-y += user.h
 generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
+generic-y += section-core.h
arch/powerpc/include/asm/Kbuild +1 -0
index 5c4fbc80dc6c..4322d9746cdb 100644
@@ -8,3 +8,4 @@ generic-y += mcs_spinlock.h
 generic-y += preempt.h
 generic-y += rwsem.h
 generic-y += vtime.h
+generic-y += section-core.h
arch/s390/include/asm/Kbuild +1 -0
index 8aea32fe8bd2..63a1c2924b91 100644
@@ -8,3 +8,4 @@ generic-y += mm-arch-hooks.h
 generic-y += preempt.h
 generic-y += trace_clock.h
 generic-y += word-at-a-time.h
+generic-y += section-core.h
arch/score/include/asm/Kbuild +1 -0
index a05218ff3fe4..f089a264cd38 100644
@@ -14,3 +14,4 @@ generic-y += trace_clock.h
 generic-y += xor.h
 generic-y += serial.h
 generic-y += word-at-a-time.h
+generic-y += section-core.h
arch/sh/include/asm/Kbuild +1 -0
index 751c3373a92c..7b0356dca562 100644
@@ -39,3 +39,4 @@ generic-y += termios.h
 generic-y += trace_clock.h
 generic-y += ucontext.h
 generic-y += xor.h
+generic-y += section-core.h
arch/sparc/include/asm/Kbuild +1 -0
index 0569bfac4afb..438f86573dc5 100644
@@ -21,3 +21,4 @@ generic-y += serial.h
 generic-y += trace_clock.h
 generic-y += types.h
 generic-y += word-at-a-time.h
+generic-y += section-core.h
arch/tile/include/asm/Kbuild +1 -0
index 2d1f5638974c..fb6b831c1fba 100644
@@ -40,3 +40,4 @@ generic-y += termios.h
 generic-y += trace_clock.h
 generic-y += types.h
 generic-y += xor.h
+generic-y += section-core.h
arch/um/include/asm/Kbuild +1 -0
index 052f7f6d0551..580bd5ff828f 100644
@@ -26,3 +26,4 @@ generic-y += topology.h
 generic-y += trace_clock.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
+generic-y += section-core.h
arch/unicore32/include/asm/section-core.h new file +19 -0
new file mode 100644
index 000000000000..0b9c68429a1a
@@ -0,0 +1,19 @@
+#ifndef __UNICORE_SECTION_CORE_ASM_H__
+#define __UNICORE_SECTION_CORE_ASM_H__
+/*
+ * Copyright (C) 2016 Luis R. Rodriguez <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of copyleft-next (version 0.3.1 or later) as published
+ * at http://copyleft-next.org/.
+ */
+
+/* Unicore32 has known to not work properly with the type set, so ignore it */
+
+#define __set_section_core_type(___section, ___core, ___name,		\
+				___level, ___flags, ___type)		\
+	.section ___section..___core.___name.___level, ___flags
+
+#include <asm-generic/section-core.h>
+
+#endif /* __UNICORE_SECTION_CORE_ASM_H__ */
arch/x86/include/asm/Kbuild +1 -0
index 2b892e2313a9..af975f21eeee 100644
@@ -12,3 +12,4 @@ generic-y += dma-contiguous.h
 generic-y += early_ioremap.h
 generic-y += mcs_spinlock.h
 generic-y += mm-arch-hooks.h
+generic-y += section-core.h
arch/xtensa/include/asm/Kbuild +1 -0
index b7fbaa56b51a..7879c31e66a7 100644
@@ -32,3 +32,4 @@ generic-y += topology.h
 generic-y += trace_clock.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
+generic-y += section-core.h
include/asm-generic/section-core.h new file +307 -0

307 lines not on this page · raw message

include/asm-generic/sections.h +2 -0
index 4df64a1fc09e..b145ae8d9cbe 100644
@@ -1,6 +1,8 @@
 #ifndef _ASM_GENERIC_SECTIONS_H_
 #define _ASM_GENERIC_SECTIONS_H_
 
+#include <asm/section-core.h>
+
 /* References to section boundaries */
 
 #include <linux/compiler.h>
include/asm-generic/vmlinux.lds.h +1 -0
index 0968d13b3885..483f60c451f9 100644
@@ -55,6 +55,7 @@
 #endif
 
 #include <linux/export.h>
+#include <asm/section-core.h>
 
 /* Align . to a 8 byte boundary equals to maximum function alignment. */
 #define ALIGN_FUNCTION()  . = ALIGN(8)
include/linux/init.h +76 -13

107 lines not on this page · raw message

include/linux/sections.h new file +87 -0

87 lines not on this page · raw message

Signature · 1 line
2.11.0
maintainer
#136 lore raw

Re: [PATCH v7 01/14] generic-sections: add section core helpers

Quoted 6 lines · Luis R. Rodriguez

Linux makes extensive use of custom ELF header sections, documentation for these are well scattered. Unify this documentation in a central place and provide helpers to build custom Linux sections.

This also generalizes sections code to enable avoiding

When you say "also" in a changelog, that's a huge flag you need to split this up. There's no reason the documentation for elf header sections has to be in the same patch as code. Please break it up.

thanks,

greg k-h

author maintainer
#137 lore raw

PATCH v7 2/14 xtensa: skip adding literal when SORT() is used

In reply to Luis R. Rodriguez

When SORT(foo.*) is used the current sed replacements add SORT(foo.literal foo.*), this breaks linking. Avoid adding literals for SORT globs, if needed, these need to be added manually.

---
 arch/xtensa/kernel/Makefile | 8 ++++----
 1 file changed, 4 insertions(+), 4 deletions(-)
arch/xtensa/kernel/Makefile +4 -4
index 264fb89c444e..ccedd016a8e0 100644
@@ -30,10 +30,10 @@ AFLAGS_mxhead.o += -mtext-section-literals
 #
 # Replicate rules in scripts/Makefile.build
 
-sed-y = -e ':a; s/\*(\([^)]*\)\.text\.unlikely/*(\1.literal.unlikely .{text}.unlikely/; ta; ' \
-	-e ':b; s/\*(\([^)]*\)\.text\(\.[a-z]*\)/*(\1.{text}\2.literal .{text}\2/; tb; ' \
-	-e ':c; s/\*(\([^)]*\)\(\.[a-z]*it\|\.ref\)\.text/*(\1\2.literal \2.{text}/; tc; ' \
-	-e ':d; s/\*(\([^)]\+ \|\)\.text/*(\1.literal .{text}/; td; ' \
+sed-y = -e ':a; s/\*(\([^)SORT]*\)\.text\.unlikely/*(\1.literal.unlikely .{text}.unlikely/; ta; ' \
+	-e ':b; s/\*(\([^)SORT]*\)\.text\(\.[a-z]*\)/*(\1.{text}\2.literal .{text}\2/; tb; ' \
+	-e ':c; s/\*(\([^SORT)]*\)\(\.[a-z]*it\|\.ref\)\.text/*(\1\2.literal \2.{text}/; tc; ' \
+	-e ':d; s/\*(\([^SORT)]\+ \|\)\.text/*(\1.literal .{text}/; td; ' \
 	-e 's/\.{text}/.text/g'
 
 quiet_cmd__cpp_lds_S = LDS     $@
Signature · 1 line
2.11.0
#138 lore raw

Re: [PATCH v7 02/14] xtensa: skip adding literal when SORT() is used

Quoted 4 lines · Luis R. Rodriguez

When SORT(foo.*) is used the current sed replacements add SORT(foo.literal foo.*), this breaks linking. Avoid adding literals for SORT globs, if needed, these need to be added manually.

Please rewrite this commit message by breaking into separate sentences, adding punctuation, etc.

Also, "the current sed replacements add" sounds really strange and makes me wonder what do you mean. What are "sed replacements"? I think you mean the "sed regex adds" from looking at the diff.

Signature · 10 lines
Regards/Gruss,
    Boris.

SUSE Linux GmbH, GF: Felix Imendörffer, Jane Smithard, Graham Norton, HRB 21284 (AG Nürnberg)
-- 

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author maintainer
#139 lore raw

PATCH v7 3/14 ranges.h: add helpers to build and identify Linux section ranges

In reply to 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 a new section range.

It turns out a lot of custom sections are actually section ranges, and these are typically spelled out in their architecture specific asm/sections.h file -- we enable architectures to override what asm is used for section ranges but start by default trusting the asm-generic version all around.

Although typically you will not want to have section ranges ordered we must use SORT() on vmlinux.lds.S for section ranges to enable us to extend a section range without modifying the linker script. To accomplish this we use a special order string for the first element of a section range -- the empty string "" (refer to __SECTION_RANGE_BEGIN()), then "~" for the last element (refer to __SECTION_RANGE_BEGIN()). If you use the "any" order for elements in between and use SORT() you end up keeping any added element in between and a reference to the beginning and end of the section range without requiring custom linker script modifications. Specific order annotations are also supported to help construct synthetic functions, a demo for which will be provided later.

v6: ran /scripts/checkpatch.pl --codespell

v5:

o Use ..rng.* instead of .rng.* as suggested by Nicholas Piggin. This is the typical way to avoid clash with compiler generated section.

o Replace section macros with section names

o Extend commit log to justify SORT() and explain why and how we use specific special strings for the beginning, end elements of a section range and the "any" order for elements in between.

o Drop SECTION_RNG_ALL() -- we no longer need this on linker scripts

o To make this easier to read, as per Nicholas Piggin, add our own SECTION_RANGE_START(), SECTION_RANGE_END(). After reviewing the changes affected by this it seemed clearer and better then to also use our own specific SECTION_RANGE_SIZE(), and SECTION_RANGE_EMPTY(), and SECTION_RANGE_ALIGNMENT() as well.

o We were using LINUX_SECTION_START() and LINUX_SECTION_END() in some places but in some other places VMLINUX_SYMBOL(name), VMLINUX_SYMBOL(name##__end). Since we are adding SECTION_RANGE_START() and SECTION_RANGE_END() just use those consistently.

o Move the linker table *(SORT(.data.rng.*)) to be present before the recently added *(.data.[0-9a-zA-Z_]*) to ensure we keep sort order on the section range.

o Adds the "Linux section ordering" documentation, as its much more relevant after this patch, in particular when treating the "any" order level.

o Fix powerpc .text use: -- it does not use TEXT_TEXT so we must add our *(SORT(.text.rng.*)) to its linker script manually.

v4:

o tons of documentation love
o fix arch/x86/tools/relocs.c typo - which caused compilation issues on old toolchains
o port to new shiny sphinx documentation
o sprinkle a few more needed VMLINUX_SYMBOL() - fixes compilation on blackfin
o name changes as suggested by Boris:
- %s/SECTION_TYPE_RANGES/rng/g
- %s/SECTION_TYPE/SECTION_CORE/g
- %s/section_type_asmtype/section_core_type/g
- %s/section_type/section_core/g
- %s/section_rng/set_section_rng/g
- rebrand DECLARE_SECTION_RNG() as DEFINE_SECTION_RANGE() - this is the asm version of the respective C version, this will have a userspace C demo added later.
o move __LINUX_RANGE() and __LINUX_RANGE_ORDER() - fixes builds on sparc
o adds section ranges to linker script
o rename SECTION_RANGE_ALL()
o use default alignment, fixes builds on powerpc and arm for both __LINUX_RANGE() and __LINUX_RANGE_ORDER()
o expand documentation to document modules support
o add maintainers
o use generic-y

v3: new in this series, uses copyleft-next

---
 Documentation/sections/index.rst        |   1 +
 Documentation/sections/ranges.rst       |  74 +++++++++++++
 Documentation/sections/section-core.rst |   5 +
 MAINTAINERS                             |  10 ++
 arch/alpha/include/asm/Kbuild           |   1 +
 arch/arc/include/asm/Kbuild             |   1 +
 arch/arm/include/asm/Kbuild             |   1 +
 arch/arm64/include/asm/Kbuild           |   1 +
 arch/avr32/include/asm/Kbuild           |   1 +
 arch/blackfin/include/asm/Kbuild        |   1 +
 arch/c6x/include/asm/Kbuild             |   1 +
 arch/cris/include/asm/Kbuild            |   1 +
 arch/frv/include/asm/Kbuild             |   1 +
 arch/h8300/include/asm/Kbuild           |   1 +
 arch/hexagon/include/asm/Kbuild         |   1 +
 arch/ia64/include/asm/Kbuild            |   1 +
 arch/m32r/include/asm/Kbuild            |   1 +
 arch/m68k/include/asm/Kbuild            |   1 +
 arch/metag/include/asm/Kbuild           |   1 +
 arch/microblaze/include/asm/Kbuild      |   1 +
 arch/mips/include/asm/Kbuild            |   1 +
 arch/mn10300/include/asm/Kbuild         |   1 +
 arch/nios2/include/asm/Kbuild           |   1 +
 arch/openrisc/include/asm/Kbuild        |   1 +
 arch/parisc/include/asm/Kbuild          |   1 +
 arch/powerpc/include/asm/Kbuild         |   1 +
 arch/powerpc/kernel/vmlinux.lds.S       |   1 +
 arch/s390/include/asm/Kbuild            |   1 +
 arch/score/include/asm/Kbuild           |   1 +
 arch/sh/include/asm/Kbuild              |   1 +
 arch/sparc/include/asm/Kbuild           |   1 +
 arch/tile/include/asm/Kbuild            |   1 +
 arch/um/include/asm/Kbuild              |   1 +
 arch/unicore32/include/asm/Kbuild       |   1 +
 arch/x86/include/asm/Kbuild             |   1 +
 arch/x86/tools/relocs.c                 |   2 +
 arch/xtensa/include/asm/Kbuild          |   1 +
 include/asm-generic/ranges.h            |  93 ++++++++++++++++
 include/asm-generic/section-core.h      |  41 +++++++
 include/asm-generic/vmlinux.lds.h       |  12 ++-
 include/linux/ranges.h                  | 183 ++++++++++++++++++++++++++++++++
 41 files changed, 451 insertions(+), 2 deletions(-)
 create mode 100644 Documentation/sections/ranges.rst
 create mode 100644 include/asm-generic/ranges.h
 create mode 100644 include/linux/ranges.h
Documentation/sections/index.rst +1 -0
index f37511ef05e7..4a1df389fa91 100644
@@ -15,3 +15,4 @@ common a set of Linux helpers for ELF sections are also documented.
 
    background
    section-core
+   ranges
Documentation/sections/ranges.rst new file +74 -0

74 lines not on this page · raw message

Documentation/sections/section-core.rst +5 -0
index ac5815a0d9b3..1f613a6c7b78 100644
@@ -114,6 +114,11 @@ Linux .ref\* sections
 .. kernel-doc:: include/asm-generic/section-core.h
    :doc: .ref.rodata
 
+Linux section ordering
+======================
+.. kernel-doc:: include/asm-generic/section-core.h
+   :doc: Linux section ordering
+
 Generic Linux kernel section helpers
 ====================================
 
MAINTAINERS +10 -0
index 5e580b1257fb..e0f29ccda90b 100644
@@ -5438,6 +5438,16 @@ S:	Supported
 F:	drivers/base/power/domain*.c
 F:	include/linux/pm_domain.h
 
+GENERIC SECTION RANGES
+M:	"Luis R. Rodriguez" <[email protected]>
+M:	"H. Peter Anvin" <[email protected]>
+L:	[email protected]
+L:	[email protected]
+S:	Supported
+F:	include/asm-generic/ranges.h
+F:	include/linux/ranges.h
+F:	Documentation/sections/ranges.rst
+
 GENERIC SECTIONS
 M:	"Luis R. Rodriguez" <[email protected]>
 M:	Josh Poimboeuf <[email protected]>
arch/alpha/include/asm/Kbuild +1 -0
index 5422827f1585..e44c896b91c4 100644
@@ -11,3 +11,4 @@ generic-y += preempt.h
 generic-y += sections.h
 generic-y += trace_clock.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/arc/include/asm/Kbuild +1 -0
index 7b2cb3dea5fc..a374b7f83888 100644
@@ -52,3 +52,4 @@ generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/arm/include/asm/Kbuild +1 -0
index 9b69a22a9ae1..0d47f98ccbc0 100644
@@ -42,3 +42,4 @@ generic-y += unaligned.h
 generated-y += mach-types.h
 generated-y += unistd-nr.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/arm64/include/asm/Kbuild +1 -0
index 00ace5e826f1..e9939cbd9067 100644
@@ -46,3 +46,4 @@ generic-y += user.h
 generic-y += vga.h
 generic-y += xor.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/avr32/include/asm/Kbuild +1 -0
index f2c3b656a0e7..edc176348d7c 100644
@@ -23,3 +23,4 @@ generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/blackfin/include/asm/Kbuild +1 -0
index bf20541bcf21..3428415b1996 100644
@@ -48,3 +48,4 @@ generic-y += user.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/c6x/include/asm/Kbuild +1 -0
index 38127ce747be..cede2a950fbf 100644
@@ -63,3 +63,4 @@ generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/cris/include/asm/Kbuild +1 -0
index 385cd88a9d9e..fb8bb4112773 100644
@@ -46,3 +46,4 @@ generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/frv/include/asm/Kbuild +1 -0
index 46d7c599d9b8..5191fec655d7 100644
@@ -9,3 +9,4 @@ generic-y += preempt.h
 generic-y += trace_clock.h
 generic-y += word-at-a-time.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/h8300/include/asm/Kbuild +1 -0
index 1ec04ec1c82b..7929a992566c 100644
@@ -76,3 +76,4 @@ generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/hexagon/include/asm/Kbuild +1 -0
index 37d7bfae7619..af17ee334788 100644
@@ -61,3 +61,4 @@ generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/ia64/include/asm/Kbuild +1 -0
index 672c6d5da18c..d8f226b35a0a 100644
@@ -10,3 +10,4 @@ generic-y += trace_clock.h
 generic-y += vtime.h
 generic-y += word-at-a-time.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/m32r/include/asm/Kbuild +1 -0
index 8ccfb5eb9678..aa9739ed9f2a 100644
@@ -13,3 +13,4 @@ generic-y += sections.h
 generic-y += trace_clock.h
 generic-y += word-at-a-time.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/m68k/include/asm/Kbuild +1 -0
index 1277b45bf4f9..006e2863ad37 100644
@@ -35,3 +35,4 @@ generic-y += types.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/metag/include/asm/Kbuild +1 -0
index b1011375cd7a..4a8471434a3e 100644
@@ -56,3 +56,4 @@ generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/microblaze/include/asm/Kbuild +1 -0
index c6c2cf6edc98..63c083a1f8da 100644
@@ -12,3 +12,4 @@ generic-y += syscalls.h
 generic-y += trace_clock.h
 generic-y += word-at-a-time.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/mips/include/asm/Kbuild +1 -0
index 7a932b4a5531..e844d6058248 100644
@@ -22,3 +22,4 @@ generic-y += user.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/mn10300/include/asm/Kbuild +1 -0
index f8145bc85835..656af7b69940 100644
@@ -11,3 +11,4 @@ generic-y += sections.h
 generic-y += trace_clock.h
 generic-y += word-at-a-time.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/nios2/include/asm/Kbuild +1 -0
index c9c7cb82b00f..c55880659d67 100644
@@ -64,3 +64,4 @@ generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/openrisc/include/asm/Kbuild +1 -0
index 86175e701869..7d6a704b808c 100644
@@ -72,3 +72,4 @@ generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/parisc/include/asm/Kbuild +1 -0
index 18a9d4c5ead7..f11d1249738f 100644
@@ -29,3 +29,4 @@ generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/powerpc/include/asm/Kbuild +1 -0
index 4322d9746cdb..60d8349241a7 100644
@@ -9,3 +9,4 @@ generic-y += preempt.h
 generic-y += rwsem.h
 generic-y += vtime.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/powerpc/kernel/vmlinux.lds.S +1 -0
index 7394b770ae1f..fcfc9d102348 100644
@@ -107,6 +107,7 @@ SECTIONS
 #endif
 		/* careful! __ftr_alt_* sections need to be close to .text */
 		*(.text .fixup __ftr_alt_* .ref.text)
+		*(SORT(.text.rng.*))
 		SCHED_TEXT
 		CPUIDLE_TEXT
 		LOCK_TEXT
arch/s390/include/asm/Kbuild +1 -0
index 63a1c2924b91..c1b85a361e5d 100644
@@ -9,3 +9,4 @@ generic-y += preempt.h
 generic-y += trace_clock.h
 generic-y += word-at-a-time.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/score/include/asm/Kbuild +1 -0
index f089a264cd38..f0cdb2cbca4d 100644
@@ -15,3 +15,4 @@ generic-y += xor.h
 generic-y += serial.h
 generic-y += word-at-a-time.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/sh/include/asm/Kbuild +1 -0
index 7b0356dca562..c9bb7932a3d1 100644
@@ -40,3 +40,4 @@ generic-y += trace_clock.h
 generic-y += ucontext.h
 generic-y += xor.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/sparc/include/asm/Kbuild +1 -0
index 438f86573dc5..28280887ac79 100644
@@ -22,3 +22,4 @@ generic-y += trace_clock.h
 generic-y += types.h
 generic-y += word-at-a-time.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/tile/include/asm/Kbuild +1 -0
index fb6b831c1fba..33f7069763ae 100644
@@ -41,3 +41,4 @@ generic-y += trace_clock.h
 generic-y += types.h
 generic-y += xor.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/um/include/asm/Kbuild +1 -0
index 580bd5ff828f..b952dcb3e216 100644
@@ -27,3 +27,4 @@ generic-y += trace_clock.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/unicore32/include/asm/Kbuild +1 -0
index 8578702d4998..93abbfdab543 100644
@@ -61,3 +61,4 @@ generic-y += user.h
 generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
+generic-y += ranges.h
arch/x86/include/asm/Kbuild +1 -0
index af975f21eeee..f672f2fc181d 100644
@@ -13,3 +13,4 @@ generic-y += early_ioremap.h
 generic-y += mcs_spinlock.h
 generic-y += mm-arch-hooks.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/x86/tools/relocs.c +2 -0
index 73eb7fd4aec4..f96fa2ddf7c9 100644
@@ -68,6 +68,8 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = {
 	"__end_rodata|"
 	"__initramfs_start|"
 	"(jiffies|jiffies_64)|"
+	".rodata..rng.*|"
+	".init.text..rng.*|"
 #if ELF_BITS == 64
 	"__per_cpu_load|"
 	"init_per_cpu__.*|"
arch/xtensa/include/asm/Kbuild +1 -0
index 7879c31e66a7..2b7fe48c0225 100644
@@ -33,3 +33,4 @@ generic-y += trace_clock.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
+generic-y += ranges.h
include/asm-generic/ranges.h new file +93 -0

93 lines not on this page · raw message

include/asm-generic/section-core.h +41 -0

47 lines not on this page · raw message

include/asm-generic/vmlinux.lds.h +10 -2
index 483f60c451f9..71bfd3b3c719 100644
@@ -56,6 +56,7 @@
 
 #include <linux/export.h>
 #include <asm/section-core.h>
+#include <asm/ranges.h>
 
 /* Align . to a 8 byte boundary equals to maximum function alignment. */
 #define ALIGN_FUNCTION()  . = ALIGN(8)
@@ -205,6 +206,7 @@
  */
 #define DATA_DATA							\
 	*(.data .data.[0-9a-zA-Z_]*)					\
+	*(SORT(.data..rng.*))						\
 	*(.ref.data)							\
 	*(.data..shared_aligned) /* percpu related */			\
 	MEM_KEEP(init.data)						\
@@ -273,7 +275,9 @@
 	. = ALIGN((align));						\
 	.rodata           : AT(ADDR(.rodata) - LOAD_OFFSET) {		\
 		VMLINUX_SYMBOL(__start_rodata) = .;			\
-		*(.rodata) *(.rodata.*)					\
+		*(.rodata)						\
+		*(SORT(.rodata..rng.*))					\
+		*(.rodata.*)						\
 		RO_AFTER_INIT_DATA	/* Read only after init */	\
 		KEEP(*(__vermagic))	/* Kernel version magic */	\
 		. = ALIGN(8);						\
@@ -446,7 +450,9 @@
  * conflicting section names, and must pull in .text.[0-9a-zA-Z_]* */
 #define TEXT_TEXT							\
 		ALIGN_FUNCTION();					\
-		*(.text.hot .text .text.fixup .text.unlikely)		\
+		*(.text.hot .text)					\
+		*(SORT(.text..rng.*))					\
+		*(.text.fixup .text.unlikely)				\
 		*(.ref.text)						\
 	MEM_KEEP(init.text)						\
 	MEM_KEEP(exit.text)						\
@@ -549,6 +555,7 @@
 #define INIT_DATA							\
 	KEEP(*(SORT(___kentry+*)))					\
 	*(.init.data)							\
+	*(SORT(.init.data..rng.*))					\
 	MEM_DISCARD(init.data)						\
 	KERNEL_CTORS()							\
 	MCOUNT_REC()							\
@@ -572,6 +579,7 @@
 
 #define INIT_TEXT							\
 	*(.init.text)							\
+	*(SORT(.init.text..rng.*))					\
 	*(.text.startup)						\
 	MEM_DISCARD(init.text)
 
include/linux/ranges.h new file +183 -0

183 lines not on this page · raw message

Signature · 1 line
2.11.0
maintainer
#140 lore raw

Re: [PATCH v7 03/14] ranges.h: add helpers to build and identify Linux section ranges

Quoted 2 lines · Luis R. Rodriguez

Section ranges are on one of the types of custom sections types used in Linux.

Argh, come on, proof-read your changelog text please!

Quoted 4 lines

This provides a series of helpers for
defining them and using them. Most importantly this also enables us to avoid modifying the linker script when we add a new section range.

Also pick a line width and stick to it!

Quoted 6 lines

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 enable architectures to override what asm is used for section ranges but start by default trusting the asm-generic version all around.

Quoted 12 lines

Although typically you will not want to have section ranges ordered we must use SORT() on vmlinux.lds.S for section ranges to enable us to extend a section range without modifying the linker script. To accomplish this we use a special order string for the first element of a section range -- the empty string "" (refer to __SECTION_RANGE_BEGIN()), then "~" for the last element (refer to __SECTION_RANGE_BEGIN()). If you use the "any" order for elements in between and use SORT() you end up keeping any added element in between and a reference to the beginning and end of the section range without requiring custom linker script modifications. Specific order annotations are also supported to help construct synthetic functions, a demo for which will be provided later.

Again, split your documentation from your coding changes to make it easier to review one or the other.

thanks,

greg k-h

author maintainer
#141 lore raw

PATCH v7 4/14 tables.h: add linker table support

In reply to 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 inspired by Michael Brown's iPXE's linker table solution, it has been been completely re-written and adapted for integration and use on Linux.

The same philosophy is borrowed, extended and further simplified:

Linker tables enable an extremely light weight linker build time solution for feature ordering and selection, this can help to both simplify init sequences in a generic fashion and helps avoiding code bit-rotting when desirable. Further changes will be added later which will make more evident how code bit rot can be avoided using linker tables.

v7: ./scripts/checkpatch.pl --codespell fixes

v6:

o rename tables macro as requested by Andy Shevchenko

v5:
o Use ..tbl.* instead of .tbl.* as suggested by Nicholas Piggin. This is the typical way to avoid clashes with compiler generated sections.
o Replace section macros with section names
o Dropped SECTION_RNG_ALL()
o Fix documentation typos
o To make this easier to read, as per Nicholas Piggin, add our own LINKTABLE_START(), LINKTABLE_END(). After reviewing the changes affected by this it seemed clearer and better then to also use our own specific LINKTABLE_SIZE(), LINKTABLE_EMPTY() and LINKTABLE_ALIGNMENT() as well.
o Clarifies SECTION_TBL_RO needs to be kept since some toolchains are buggy, and so we also add SECTION_TBL_RO_STR.
o We were using LINUX_SECTION_START() and LINUX_SECTION_END() in some places but in some other places VMLINUX_SYMBOL(name), VMLINUX_SYMBOL(name##__end). Since we are adding LINKTABLE_START() and LINKTABLE_END() just use those consistently.
o Fix DEFINE_LINKTABLE_INIT() by making it use DECLARE_LINKTABLE_RO() which forces const.
o Fix powerpc .text use: it does not use TEXT_TEXT so we must add our *(SORT(.text.tbl.*)) to its linker script manually.

v4:

o Split out kbuild additions to help with code bit rot into its own patch
o tons of documentation love
o fix arch/x86/tools/relocs.c typo - which caused compilation issues on old toolchains
o add c6x toolchain work around as discussed with Mark Salter
o sprinkle a few more needed VMLINUX_SYMBOL() - fixes compilation on blackfin
o suggested name changes by boris:
- %s/SECTION_TYPE_RANGES/rng/g
- %s/SECTION_TYPE/SECTION_CORE/g
- %s/section_type_asmtype/section_core_type/g
- %s/section_type/section_core/g
- %s/section_rng/set_section_rng/g
- Drop DECLARE_SECTION_TBL() -- this is an asm equivalent DEFINE_LINKTABLE() -- this however is not used yet, and it requires a bit more work to match the C code definitions.
o drop tools/include/linux/sections.h in favor of the more popular open coding the names for tools
o expand documentation to include module support
o add maintaners
o Use generic-y
o move .text.tbl before unlikely to match the other sections

v3:

o addressed initial modular support test cases
o added generic asm macros so linker tables can be used in asm code / C asm calls
o section ranges are now split up into their own set of files
o use asm/sections.h instead of linux/sections.h for the linker script
o add a sections.h file for each architecture that was missing one, this is needed now as we'll be relying on sections.h for custom section types in code rather than custom architecture specific linker script hacks.
o full rewrite at this point, decided to pick copyleft-next license for this work

v2:

o modified completely to match feedback by community, made equivalent modifications to userspace solution. This is pretty much a complete rewrite of how we present and use linker tables. By using standard sections we no longer have to make custom linker script extensions for each new linker table solution, you just pick a linker table type by section type.
o extend documention considerably, including use of kdoc
o drop ICC hacks per popular request to ignore such issues for now
o use sections.h - this lets us streamline a clean use case of well documented sections. To help further with this make use of SECTION_TBL() to allow use of these in code and SECTION_TBL_ALL() on linker scripts, as well as SECTION_TBL_ALL_STR() on relocs.c when needed.

---
 Documentation/sections/index.rst         |   1 +
 Documentation/sections/linker-tables.rst | 212 +++++++++++
 MAINTAINERS                              |  10 +
 arch/alpha/include/asm/Kbuild            |   1 +
 arch/arc/include/asm/Kbuild              |   1 +
 arch/arm/include/asm/Kbuild              |   1 +
 arch/arm64/include/asm/Kbuild            |   1 +
 arch/avr32/include/asm/Kbuild            |   1 +
 arch/blackfin/include/asm/Kbuild         |   1 +
 arch/c6x/include/asm/tables.h            |  26 ++
 arch/cris/include/asm/Kbuild             |   1 +
 arch/frv/include/asm/Kbuild              |   1 +
 arch/h8300/include/asm/Kbuild            |   1 +
 arch/hexagon/include/asm/Kbuild          |   1 +
 arch/ia64/include/asm/Kbuild             |   1 +
 arch/m32r/include/asm/Kbuild             |   1 +
 arch/m68k/include/asm/Kbuild             |   1 +
 arch/metag/include/asm/Kbuild            |   1 +
 arch/microblaze/include/asm/Kbuild       |   1 +
 arch/mips/include/asm/Kbuild             |   1 +
 arch/mn10300/include/asm/Kbuild          |   1 +
 arch/nios2/include/asm/Kbuild            |   1 +
 arch/openrisc/include/asm/Kbuild         |   1 +
 arch/parisc/include/asm/Kbuild           |   1 +
 arch/powerpc/include/asm/Kbuild          |   1 +
 arch/powerpc/kernel/vmlinux.lds.S        |   1 +
 arch/s390/include/asm/Kbuild             |   1 +
 arch/score/include/asm/Kbuild            |   1 +
 arch/sh/include/asm/Kbuild               |   1 +
 arch/sparc/include/asm/Kbuild            |   1 +
 arch/tile/include/asm/Kbuild             |   1 +
 arch/um/include/asm/Kbuild               |   1 +
 arch/unicore32/include/asm/Kbuild        |   1 +
 arch/x86/include/asm/Kbuild              |   1 +
 arch/x86/tools/relocs.c                  |   2 +
 arch/xtensa/include/asm/Kbuild           |   1 +
 include/asm-generic/tables.h             |  48 +++
 include/asm-generic/vmlinux.lds.h        |   6 +
 include/linux/tables.h                   | 612 +++++++++++++++++++++++++++++++
 39 files changed, 948 insertions(+)
 create mode 100644 Documentation/sections/linker-tables.rst
 create mode 100644 arch/c6x/include/asm/tables.h
 create mode 100644 include/asm-generic/tables.h
 create mode 100644 include/linux/tables.h
Documentation/sections/index.rst +1 -0
index 4a1df389fa91..7c7c1adf955c 100644
@@ -16,3 +16,4 @@ common a set of Linux helpers for ELF sections are also documented.
    background
    section-core
    ranges
+   linker-tables
Documentation/sections/linker-tables.rst new file +207 -0

207 lines not on this page · raw message

MAINTAINERS +10 -0
index e0f29ccda90b..99ca436e76d9 100644
@@ -5421,6 +5421,16 @@ S:	Maintained
 F:	include/asm-generic/
 F:	include/uapi/asm-generic/
 
+GENERIC LINKER TABLES
+M:	"Luis R. Rodriguez" <[email protected]>
+M:	"H. Peter Anvin" <[email protected]>
+L:	[email protected]
+L:	[email protected]
+S:	Supported
+F:	include/asm-generic/tables.h
+F:	include/linux/tables.h
+F:	Documentation/sections/linker-tables.rst
+
 GENERIC PHY FRAMEWORK
 M:	Kishon Vijay Abraham I <[email protected]>
 L:	[email protected]
arch/alpha/include/asm/Kbuild +1 -0
index e44c896b91c4..f3bdc31d3c97 100644
@@ -12,3 +12,4 @@ generic-y += sections.h
 generic-y += trace_clock.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/arc/include/asm/Kbuild +1 -0
index a374b7f83888..ccfa69ce2608 100644
@@ -53,3 +53,4 @@ generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/arm/include/asm/Kbuild +1 -0
index 0d47f98ccbc0..b70d4b78d577 100644
@@ -43,3 +43,4 @@ generated-y += mach-types.h
 generated-y += unistd-nr.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/arm64/include/asm/Kbuild +1 -0
index e9939cbd9067..0c1e781ab10b 100644
@@ -47,3 +47,4 @@ generic-y += vga.h
 generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/avr32/include/asm/Kbuild +1 -0
index edc176348d7c..a6cd145515ae 100644
@@ -24,3 +24,4 @@ generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/blackfin/include/asm/Kbuild +1 -0
index 3428415b1996..9115b215fc7e 100644
@@ -49,3 +49,4 @@ generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/c6x/include/asm/tables.h new file +26 -0
new file mode 100644
index 000000000000..90a0d3df35c8
@@ -0,0 +1,26 @@
+#ifndef _ASM_C6X_ASM_TABLES_H
+#define _ASM_C6X_ASM_TABLES_H
+/*
+ * Copyright (C) 2016 Luis R. Rodriguez <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of copyleft-next (version 0.3.1 or later) as published
+ * at http://copyleft-next.org/.
+ */
+
+/*
+ * The c6x toolchain has a bug present even on gcc-6 when non-weak attributes
+ * are used and sends them to .rodata even though const data with weak
+ * attributes are put in .const, this forces the linker to believe the address
+ * is relative relative to the a base + offset and you end up with SB-relative
+ * reloc error upon linking. Work around this by by forcing both start and
+ * ending const RO weak linker table entry to be .const to fix this for now.
+ *
+ * [0] https://lkml.kernel.org/r/[email protected]
+ */
+
+#define SECTION_TBL_RO		.const
+
+#include <asm-generic/tables.h>
+
+#endif /* _ASM_C6X_ASM_TABLES_H */
arch/cris/include/asm/Kbuild +1 -0
index fb8bb4112773..7062c1be7913 100644
@@ -47,3 +47,4 @@ generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/frv/include/asm/Kbuild +1 -0
index 5191fec655d7..4a59cbda5091 100644
@@ -10,3 +10,4 @@ generic-y += trace_clock.h
 generic-y += word-at-a-time.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/h8300/include/asm/Kbuild +1 -0
index 7929a992566c..d79968d93c12 100644
@@ -77,3 +77,4 @@ generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/hexagon/include/asm/Kbuild +1 -0
index af17ee334788..d59ac1c1858b 100644
@@ -62,3 +62,4 @@ generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/ia64/include/asm/Kbuild +1 -0
index d8f226b35a0a..76540f143473 100644
@@ -11,3 +11,4 @@ generic-y += vtime.h
 generic-y += word-at-a-time.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/m32r/include/asm/Kbuild +1 -0
index aa9739ed9f2a..f3f1e51dd5be 100644
@@ -14,3 +14,4 @@ generic-y += trace_clock.h
 generic-y += word-at-a-time.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/m68k/include/asm/Kbuild +1 -0
index 006e2863ad37..c28bcdecc764 100644
@@ -36,3 +36,4 @@ generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/metag/include/asm/Kbuild +1 -0
index 4a8471434a3e..c836f7e2a5e7 100644
@@ -57,3 +57,4 @@ generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/microblaze/include/asm/Kbuild +1 -0
index 63c083a1f8da..01afb1b420f5 100644
@@ -13,3 +13,4 @@ generic-y += trace_clock.h
 generic-y += word-at-a-time.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/mips/include/asm/Kbuild +1 -0
index e844d6058248..db9dff9c1535 100644
@@ -23,3 +23,4 @@ generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/mn10300/include/asm/Kbuild +1 -0
index 656af7b69940..6c8d12f3fe44 100644
@@ -12,3 +12,4 @@ generic-y += trace_clock.h
 generic-y += word-at-a-time.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/nios2/include/asm/Kbuild +1 -0
index c55880659d67..ee6220dac1e8 100644
@@ -65,3 +65,4 @@ generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/openrisc/include/asm/Kbuild +1 -0
index 7d6a704b808c..ceafe458e295 100644
@@ -73,3 +73,4 @@ generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/parisc/include/asm/Kbuild +1 -0
index f11d1249738f..aaae8a9f6099 100644
@@ -30,3 +30,4 @@ generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/powerpc/include/asm/Kbuild +1 -0
index 60d8349241a7..7c06627a0a0d 100644
@@ -10,3 +10,4 @@ generic-y += rwsem.h
 generic-y += vtime.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/powerpc/kernel/vmlinux.lds.S +1 -0
index fcfc9d102348..8cd940c72895 100644
@@ -108,6 +108,7 @@ SECTIONS
 		/* careful! __ftr_alt_* sections need to be close to .text */
 		*(.text .fixup __ftr_alt_* .ref.text)
 		*(SORT(.text.rng.*))
+		*(SORT(.text..tbl.*))
 		SCHED_TEXT
 		CPUIDLE_TEXT
 		LOCK_TEXT
arch/s390/include/asm/Kbuild +1 -0
index c1b85a361e5d..96dd69931427 100644
@@ -10,3 +10,4 @@ generic-y += trace_clock.h
 generic-y += word-at-a-time.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/score/include/asm/Kbuild +1 -0
index f0cdb2cbca4d..16ea15a3e432 100644
@@ -16,3 +16,4 @@ generic-y += serial.h
 generic-y += word-at-a-time.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/sh/include/asm/Kbuild +1 -0
index c9bb7932a3d1..d0ea768d15ae 100644
@@ -41,3 +41,4 @@ generic-y += ucontext.h
 generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/sparc/include/asm/Kbuild +1 -0
index 28280887ac79..23a2216f4146 100644
@@ -23,3 +23,4 @@ generic-y += types.h
 generic-y += word-at-a-time.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/tile/include/asm/Kbuild +1 -0
index 33f7069763ae..a599f6f4ee0a 100644
@@ -42,3 +42,4 @@ generic-y += types.h
 generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/um/include/asm/Kbuild +1 -0
index b952dcb3e216..d2867aa09e23 100644
@@ -28,3 +28,4 @@ generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/unicore32/include/asm/Kbuild +1 -0
index 93abbfdab543..6671a1f08ead 100644
@@ -62,3 +62,4 @@ generic-y += vga.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += ranges.h
+generic-y += tables.h
arch/x86/include/asm/Kbuild +1 -0
index f672f2fc181d..4cb511f1067c 100644
@@ -14,3 +14,4 @@ generic-y += mcs_spinlock.h
 generic-y += mm-arch-hooks.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/x86/tools/relocs.c +2 -0
index f96fa2ddf7c9..484a24c309fb 100644
@@ -69,7 +69,9 @@ static const char * const sym_regex_kernel[S_NSYMTYPES] = {
 	"__initramfs_start|"
 	"(jiffies|jiffies_64)|"
 	".rodata..rng.*|"
+	".rodata..tbl.*|"
 	".init.text..rng.*|"
+	".init.text..tbl.*|"
 #if ELF_BITS = 64
 	"__per_cpu_load|"
 	"init_per_cpu__.*|"
arch/xtensa/include/asm/Kbuild +1 -0
index 2b7fe48c0225..7b41f32a2ba0 100644
@@ -34,3 +34,4 @@ generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
include/asm-generic/tables.h new file +48 -0

48 lines not on this page · raw message

include/asm-generic/vmlinux.lds.h +6 -0
index 71bfd3b3c719..ce1e9a310ada 100644
@@ -57,6 +57,7 @@
 #include <linux/export.h>
 #include <asm/section-core.h>
 #include <asm/ranges.h>
+#include <asm/tables.h>
 
 /* Align . to a 8 byte boundary equals to maximum function alignment. */
 #define ALIGN_FUNCTION()  . = ALIGN(8)
@@ -207,6 +208,7 @@
 #define DATA_DATA							\
 	*(.data .data.[0-9a-zA-Z_]*)					\
 	*(SORT(.data..rng.*))						\
+	*(SORT(.data..tbl.*))						\
 	*(.ref.data)							\
 	*(.data..shared_aligned) /* percpu related */			\
 	MEM_KEEP(init.data)						\
@@ -277,6 +279,7 @@
 		VMLINUX_SYMBOL(__start_rodata) = .;			\
 		*(.rodata)						\
 		*(SORT(.rodata..rng.*))					\
+		*(SORT(.rodata..tbl.*))					\
 		*(.rodata.*)						\
 		RO_AFTER_INIT_DATA	/* Read only after init */	\
 		KEEP(*(__vermagic))	/* Kernel version magic */	\
@@ -452,6 +455,7 @@
 		ALIGN_FUNCTION();					\
 		*(.text.hot .text)					\
 		*(SORT(.text..rng.*))					\
+		*(SORT(.text..tbl.*))					\
 		*(.text.fixup .text.unlikely)				\
 		*(.ref.text)						\
 	MEM_KEEP(init.text)						\
@@ -556,6 +560,7 @@
 	KEEP(*(SORT(___kentry+*)))					\
 	*(.init.data)							\
 	*(SORT(.init.data..rng.*))					\
+	*(SORT(.init.data..tbl.*))					\
 	MEM_DISCARD(init.data)						\
 	KERNEL_CTORS()							\
 	MCOUNT_REC()							\
@@ -580,6 +585,7 @@
 #define INIT_TEXT							\
 	*(.init.text)							\
 	*(SORT(.init.text..rng.*))					\
+	*(SORT(.init.text..tbl.*))					\
 	*(.text.startup)						\
 	MEM_DISCARD(init.text)
 
include/linux/tables.h new file +612 -0

612 lines not on this page · raw message

Signature · 1 line
2.11.0
maintainer
#142 lore raw

Re: [PATCH v7 04/14] tables.h: add linker table support

Quoted 8 lines · 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 inspired by Michael Brown's iPXE's linker table solution, it has been been completely re-written and adapted for integration and use on Linux.

Ok, I understand that, but then you say:

Quoted 1 line

The same philosophy is borrowed, extended and further simplified:

This line made no sense :(

Quoted 6 lines

Linker tables enable an extremely light weight linker build time solution for feature ordering and selection, this can help to both simplify init sequences in a generic fashion and helps avoiding code bit-rotting when desirable. Further changes will be added later which will make more evident how code bit rot can be avoided using linker tables.

I have no idea why this is needed, nor what it means. I fail to understand the bit-rot reference.

thanks,

greg k-h

author maintainer
#143 lore raw

PATCH v7 5/14 kbuild: enable option to force compile force-obj-y and force-lib-y

In reply to Luis R. Rodriguez

Linux provides a rich array of features, enabling each feature however increases the size of the kernel and there are many features which users often want disabled. The traditional solution to this problem is for each feature to have its own Kconfig symbol, followed by a series of #ifdef statements in C code and header files, allowing the feature to be compiled only when desirable. As the variability of Linux increases build tests can and are often done with random kernel configurations, allyesconfig, and allmodconfig to help find code issues. This however doesn't catch all errors and as a consequence code that is typically not enabled often can suffer from bit-rot over time.

An alternative approach for subsystems, which refer to as the 'build-all link-selectively philosophy' is to keep the Kconfig symbols, replace the #ifdef approach by having each feature implemented it its own C file, and force compilation for all features to avoid the code bit-rot problem. With this strategy only features that are enabled via Kconfig get linked into the kernel, so the forced compilation has no size impact on the kernel. The practice of having each feature implemented in its own C file is already prevalent in many subsystems, however #ifdefs are still typically required during feature initialization. For instance in:

  #ifdef CONFIG_FOO
  foo_init();
  #endif

We cannot remove the #ifdef and leave foo_init() as we'd either need to always enable the feature or add a respective #ifdef in a foo.h which makes foo_init() do nothing when CONFIG_FOO is disabled.

Linker tables enable lifting the requirement to use of #ifdefs during initialization. With linker tables initialization sequences can instead be aggregated into a custom ELF section at link time, during run time the table can be iterated over and each init sequence enabled can be called. A feature's init routine is only added to a table when its respective Kconfig symbols has been enabled and therefore linked in. Linker tables enable subsystems to completely do away with #ifdefs if one is comfortable in accepting all subsystem's feature's structural size implications.

Subsystems which want to follow the 'build-all link-selectively philosophy' still need a way to easily express and annotate that they wish for all code to always be compiled to help avoid code bit rot, as such two new targets force-obj-y and force-lib-y are provided to help with this. Its not fair to require everyone to force compilation of all features of a subsystem though, so as a compromise, the new targets only force compilation when CONFIG_BUILD_AVOID_BITROT is enabled.

Only built-in features are supported at the moment. Module support is expected to be added after a generic solution to add linker tables to modules more easily is developed.

v4: this patch was added to this series, it was split off from the
linker tables addition due to the confusion over the code bit rot alternatives that are possible with linker tables.

---
 Documentation/kbuild/makefiles.txt       | 36 ++++++++++++++++
 Documentation/sections/linker-tables.rst | 15 +++++++
 include/linux/tables.h                   | 71 ++++++++++++++++++++++++++++++++
 init/Kconfig                             | 22 ++++++++++
 scripts/Makefile.build                   |  7 ++--
 scripts/Makefile.clean                   |  2 +
 scripts/Makefile.lib                     | 11 +++++
 7 files changed, 161 insertions(+), 3 deletions(-)
Documentation/kbuild/makefiles.txt +36 -0
index 9b9c4797fc55..1af275cd4879 100644
@@ -1090,6 +1090,42 @@ When kbuild executes, the following steps are followed (roughly):
 	In this example, extra-y is used to list object files that
 	shall be built, but shall not be linked as part of built-in.o.
 
+    force-obj-y force-lib-y
+
+	When CONFIG_BUILD_AVOID_BITROT is enabled using these targets for your
+	kconfig symbols forces compilation of the associated objects if the
+	kconfig's symbol's dependencies are met, the objects however are only
+	linked into to the kernel if and only if the kconfig symbol was
+	enabled. If CONFIG_BUILD_AVOID_BITROT is disabled the force-obj-y and
+	force-lib-y targets are functionally equilvalent to obj-y and lib-y
+	respectively.
+
+	Using force-obj-y and force-lib-y are part of a code architecture and
+	build philosophy further enabled by linker tables, for more details
+	refer to the documention in include/linux/tables.h, refer to the
+	sections:
+
+		o The code bit-rot problem
+		o The build-all selective-link philosophy
+		o Avoiding the code bit-rot problem with linker tables
+		o Linker table module support
+
+	Modules support is expected to be enhanced in the future, so for now
+	only built-in features are supported.
+
+	Example use:
+
+		force-obj-$(CONFIG_FEATURE_FOO) += foo.o
+
+	An alternative to using force-obj-y, is to use extra-y followed by the
+	respective obj-y:
+
+		extra-y += foo.o
+		obj-$(CONFIG_FEATURE_FOO) += foo.o
+
+	Using force-obj-y and force-lib-y can be used to help annotate the
+	targets follow the 'build-all selective-link philosophy' further
+	enabled by linker tables.
 
 --- 6.7 Commands useful for building a boot image
 
Documentation/sections/linker-tables.rst +15 -0
index 780a292d2d00..bc2d9f46cde6 100644
@@ -30,6 +30,21 @@ How linker tables simplify initialization code
 .. kernel-doc:: include/linux/tables.h
    :doc: How linker tables simplify initialization code
 
+The code bit-rot problem
+------------------------
+.. kernel-doc:: include/linux/tables.h
+   :doc: The code bit-rot problem
+
+The build-all selective-link philosophy
+---------------------------------------
+.. kernel-doc:: include/linux/tables.h
+   :doc: The build-all selective-link philosophy
+
+Avoiding the code bit-rot problem with linker tables
+----------------------------------------------------
+.. kernel-doc:: include/linux/tables.h
+   :doc: Avoiding the code bit-rot problem with linker tables
+
 Using linker tables in Linux
 ============================
 
include/linux/tables.h +71 -0

77 lines not on this page · raw message

init/Kconfig +22 -0
index 536c2a00d972..6272f4fdcc86 100644
@@ -63,6 +63,28 @@ config CROSS_COMPILE
 	  need to set this unless you want the configured kernel build
 	  directory to select the cross-compiler automatically.
 
+config BUILD_AVOID_BITROT
+	bool "Enable force building of force-obj-y and force-lib-y"
+	default n
+	help
+	  When enabled objects under the force-obj-y and force-lib-y targets
+	  using a Kconfig symbol will be forced to compile if the Kconfig
+	  symbol's dependencies are met but only linked into the kernel if
+	  the Kconfig symbol is enabled. If a Kconfig symbol on a force-obj-y
+	  or force-lib-y target is disabled, it will be compiled but not linked
+	  into the kernel.
+
+	  The force-obj-y and force-lib-y targets can be used by subsystems
+	  which wish to want to follow the 'build-all selective-link philosophy'
+	  documented under include/linux/tables.h.
+
+	  Say Y if you have a decent build machine and would like to help test
+	  building code for more subsystems. Say N if you do you not have a
+	  good build machine or only want to compile what you've enabled for
+	  your kernel.
+
+	  Enabling this option never increases the size of your kernel.
+
 config COMPILE_TEST
 	bool "Compile also drivers which will not load"
 	depends on !UML
scripts/Makefile.build +4 -3
index eadcd4d359d9..c34af839d47c 100644
@@ -92,7 +92,8 @@ modorder-target := $(obj)/modules.order
 
 # We keep a list of all modules in $(MODVERDIR)
 
-__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y)) \
+__build: $(if $(KBUILD_BUILTIN),$(builtin-target) $(lib-target) $(extra-y) \
+				$(force-obj-y)) \
 	 $(if $(KBUILD_MODULES),$(obj-m) $(modorder-target)) \
 	 $(subdir-ym) $(always)
 	@:
@@ -392,8 +393,8 @@ endif
 $(obj)/%.o: $(src)/%.S $(objtool_obj) FORCE
 	$(call if_changed_rule,as_o_S)
 
-targets += $(real-objs-y) $(real-objs-m) $(lib-y)
-targets += $(extra-y) $(MAKECMDGOALS) $(always)
+targets += $(real-objs-y) $(real-objs-m) $(lib-y) $(force-lib-y)
+targets += $(extra-y) $(force-obj-y) $(MAKECMDGOALS) $(always)
 
 # Linker scripts preprocessor (.lds.S -> .lds)
 # ---------------------------------------------------------------------------
scripts/Makefile.clean +2 -0
index 50616ea25131..2b54546237d6 100644
@@ -36,6 +36,8 @@ subdir-ymn	:= $(addprefix $(obj)/,$(subdir-ymn))
 # directory
 
 __clean-files	:= $(extra-y) $(extra-m) $(extra-)       \
+		   $(force-obj-y) $(force-obj-m) $(force-obj-)       \
+		   $(force-lib-y) $(force-lib-m) $(force-lib-)       \
 		   $(always) $(targets) $(clean-files)   \
 		   $(host-progs)                         \
 		   $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
scripts/Makefile.lib +11 -0
index 0a07f9014944..d1cb0cfdf1bf 100644
@@ -12,6 +12,15 @@ export KBUILD_SUBDIR_CCFLAGS := $(KBUILD_SUBDIR_CCFLAGS) $(subdir-ccflags-y)
 # Figure out what we need to build from the various variables
 # ===========================================================================
 
+ifeq ($(CONFIG_BUILD_AVOID_BITROT),y)
+extra-y += $(force-obj-) $(force-lib-)
+endif
+
+obj-m += $(force-obj-m)
+obj-y += $(force-obj-y)
+lib-m += $(force-lib-m)
+lib-y += $(force-lib-y)
+
 # When an object is listed to be built compiled-in and modular,
 # only build the compiled-in version
 
@@ -72,6 +81,8 @@ real-objs-m := $(foreach m, $(obj-m), $(if $(strip $($(m:.o=-objs)) $($(m:.o=-y)
 # Add subdir path
 
 extra-y		:= $(addprefix $(obj)/,$(extra-y))
+force-obj-y		:= $(addprefix $(obj)/,$(force-obj-y))
+force-obj-m		:= $(addprefix $(obj)/,$(force-obj-m))
 always		:= $(addprefix $(obj)/,$(always))
 targets		:= $(addprefix $(obj)/,$(targets))
 modorder	:= $(addprefix $(obj)/,$(modorder))
Signature · 1 line
2.11.0
maintainer
#144 lore raw

Re: [PATCH v7 05/14] kbuild: enable option to force compile force-obj-y and force-lib-y

Quoted 11 lines · Luis R. Rodriguez

Linux provides a rich array of features, enabling each feature however increases the size of the kernel and there are many features which users often want disabled. The traditional solution to this problem is for each feature to have its own Kconfig symbol, followed by a series of #ifdef statements in C code and header files, allowing the feature to be compiled only when desirable. As the variability of Linux increases build tests can and are often done with random kernel configurations, allyesconfig, and allmodconfig to help find code issues. This however doesn't catch all errors and as a consequence code that is typically not enabled often can suffer from bit-rot over time.

Really? How do you know this, our test-build infrastructure is really good, what has rotted with it?

And again, pick a column width and stick with it in the whole changelog...

Quoted 10 lines

An alternative approach for subsystems, which refer to as the 'build-all link-selectively philosophy' is to keep the Kconfig symbols, replace the #ifdef approach by having each feature implemented it its own C file, and force compilation for all features to avoid the code bit-rot problem. With this strategy only features that are enabled via Kconfig get linked into the kernel, so the forced compilation has no size impact on the kernel. The practice of having each feature implemented in its own C file is already prevalent in many subsystems, however #ifdefs are still typically required during feature initialization. For instance in:

Quoted 3 lines
  #ifdef CONFIG_FOO
  foo_init();
  #endif

That's horrid kernel code, and shouldn't be an example of anything other than what NOT to do. You know better than this, put the #ifdef in a .h file.

Quoted 3 lines

We cannot remove the #ifdef and leave foo_init() as we'd either need to always enable the feature or add a respective #ifdef in a foo.h which makes foo_init() do nothing when CONFIG_FOO is disabled.

Yes, and what's wrong with that?

Quoted 10 lines

Linker tables enable lifting the requirement to use of #ifdefs during initialization. With linker tables initialization sequences can instead be aggregated into a custom ELF section at link time, during run time the table can be iterated over and each init sequence enabled can be called. A feature's init routine is only added to a table when its respective Kconfig symbols has been enabled and therefore linked in. Linker tables enable subsystems to completely do away with #ifdefs if one is comfortable in accepting all subsystem's feature's structural size implications.

Quoted 8 lines

Subsystems which want to follow the 'build-all link-selectively philosophy' still need a way to easily express and annotate that they wish for all code to always be compiled to help avoid code bit rot, as such two new targets force-obj-y and force-lib-y are provided to help with this. Its not fair to require everyone to force compilation of all features of a subsystem though, so as a compromise, the new targets only force compilation when CONFIG_BUILD_AVOID_BITROT is enabled.

You do know about COMPILE_TEST, right? What's wrong with that? Why not use that as-is today and not add a new configuration option?

Quoted 3 lines

Only built-in features are supported at the moment. Module support is expected to be added after a generic solution to add linker tables to modules more easily is developed.

Ok, you are talking about majorly changing how the kernel build system works. What do the kbuild developers/maintainers say about this?

Quoted 194 lines

v4: this patch was added to this series, it was split off from the
linker tables addition due to the confusion over the code bit rot alternatives that are possible with linker tables.

---
 Documentation/kbuild/makefiles.txt       | 36 ++++++++++++++++
 Documentation/sections/linker-tables.rst | 15 +++++++
 include/linux/tables.h                   | 71 ++++++++++++++++++++++++++++++++
 init/Kconfig                             | 22 ++++++++++
 scripts/Makefile.build                   |  7 ++--
 scripts/Makefile.clean                   |  2 +
 scripts/Makefile.lib                     | 11 +++++
 7 files changed, 161 insertions(+), 3 deletions(-)
Documentation/kbuild/makefiles.txt +36 -0
index 9b9c4797fc55..1af275cd4879 100644
@@ -1090,6 +1090,42 @@ When kbuild executes, the following steps are followed (roughly):
 	In this example, extra-y is used to list object files that
 	shall be built, but shall not be linked as part of built-in.o.
 
+    force-obj-y force-lib-y
+
+	When CONFIG_BUILD_AVOID_BITROT is enabled using these targets for your
+	kconfig symbols forces compilation of the associated objects if the
+	kconfig's symbol's dependencies are met, the objects however are only
+	linked into to the kernel if and only if the kconfig symbol was
+	enabled. If CONFIG_BUILD_AVOID_BITROT is disabled the force-obj-y and
+	force-lib-y targets are functionally equilvalent to obj-y and lib-y
+	respectively.
+
+	Using force-obj-y and force-lib-y are part of a code architecture and
+	build philosophy further enabled by linker tables, for more details
+	refer to the documention in include/linux/tables.h, refer to the
+	sections:
+
+		o The code bit-rot problem
+		o The build-all selective-link philosophy
+		o Avoiding the code bit-rot problem with linker tables
+		o Linker table module support
+
+	Modules support is expected to be enhanced in the future, so for now
+	only built-in features are supported.
+
+	Example use:
+
+		force-obj-$(CONFIG_FEATURE_FOO) += foo.o
+
+	An alternative to using force-obj-y, is to use extra-y followed by the
+	respective obj-y:
+
+		extra-y += foo.o
+		obj-$(CONFIG_FEATURE_FOO) += foo.o
+
+	Using force-obj-y and force-lib-y can be used to help annotate the
+	targets follow the 'build-all selective-link philosophy' further
+	enabled by linker tables.
 
 --- 6.7 Commands useful for building a boot image
 
Documentation/sections/linker-tables.rst +15 -0
index 780a292d2d00..bc2d9f46cde6 100644
@@ -30,6 +30,21 @@ How linker tables simplify initialization code
 .. kernel-doc:: include/linux/tables.h
    :doc: How linker tables simplify initialization code
 
+The code bit-rot problem
+------------------------
+.. kernel-doc:: include/linux/tables.h
+   :doc: The code bit-rot problem
+
+The build-all selective-link philosophy
+---------------------------------------
+.. kernel-doc:: include/linux/tables.h
+   :doc: The build-all selective-link philosophy
+
+Avoiding the code bit-rot problem with linker tables
+----------------------------------------------------
+.. kernel-doc:: include/linux/tables.h
+   :doc: Avoiding the code bit-rot problem with linker tables
+
 Using linker tables in Linux
 ============================
 
include/linux/tables.h +71 -0
index 82da59c4266d..f295fbe74734 100644
@@ -169,6 +169,77 @@
  */
 
 /**
+ * DOC: The code bit-rot problem
+ *
+ * Linux provides a rich array of features, enabling each feature
+ * however increases the size of the kernel and there are many
+ * features which users often want disabled. The traditional
+ * solution to this problem is for each feature to have its own
+ * Kconfig symbol, followed by a series of #ifdef statements
+ * in C code and header files, allowing the feature to be compiled
+ * only when desirable. As the variability of Linux increases build
+ * tests can and are often done with random kernel configurations,
+ * allyesconfig, and allmodconfig to help find code issues. This
+ * however doesn't catch all errors and as a consequence code that
+ * is typically not enabled often can suffer from bit-rot over time.
+ */
+
+/**
+ * DOC: The build-all selective-link philosophy
+ *
+ * A code architecture philosophy to help avoid code bit-rot consists
+ * of using Kconfig symbols for each subsystem feature, replace all #ifdefs
+ * by instead having each feature implemented it its own C file, and force
+ * compilation for all features. Only features that are enabled get linked in,
+ * the forced compilation therefore has no size impact on the final result of
+ * the kernel. The practice of having each feature implemented in its own C
+ * file is already prevalent in many subsystems, however #ifdefs are still
+ * typically required during feature initialization. For instance in::
+ *
+ *	#ifdef CONFIG_FOO
+ *	foo_init();
+ *	#endif
+ *
+ * We cannot remove the #ifdef and leave foo_init() as we'd either
+ * need to always enable the feature or add a respective #ifdef in a
+ * foo.h which makes foo_init() do nothing when ``CONFIG_FOO`` is disabled.
+ */
+
+/**
+ * DOC: Avoiding the code bit-rot problem with linker tables
+ *
+ * Linker tables can be used to further help avoid the code bit-rot problem
+ * when embracing the 'build-all selective-link philosophy' by lifting the
+ * requirement to use of #ifdefs during initialization. With linker tables
+ * initialization sequences can be aggregated into a custom ELF section at
+ * link time, during run time the table can be iterated over and each init
+ * sequence enabled can be called. A feature's init routine is only added to a
+ * table when its respective Kconfig symbols has been enabled and therefore
+ * linked in. Linker tables enable subsystems to completely do away with
+ * #ifdefs if one is comfortable in accepting all subsystem's feature's
+ * structural size implications.
+ *
+ * To further help with this the Linux build system supports two special
+ * targets, ``force-obj-y`` and ``force-lib-y``. A subsystem which wants to
+ * follow the 'build-all selective-link philosophy' can use these targets for a
+ * feature's kconfig symbol. Using these targets will always require
+ * compilation of the kconfig's objects if the kconfig symbol's dependencies
+ * are met but only link the objects into the kernel, and therefore enable the
+ * feature, if and only if the kconfig symbol has been enabled.
+ *
+ * Not all users or build systems may want to opt-in to compile all objects
+ * following the 'build-all selective-link philosophy', as such the targets
+ * ``force-obj-y`` and ``force-lib-y`` only force compilation when the kconfig
+ * symbol ``CONFIG_BUILD_AVOID_BITROT`` has been enabled. Disabling this feature
+ * makes ``force-obj-y`` and ``force-lib-y`` functionally equivalent to
+ * ``obj-y`` and ``lib-y`` respectively.
+ *
+ * Example use::
+ *
+ *	force-obj-$(CONFIG_FEATURE_FOO) += foo.o
+ */
+
+/**
  * DOC: Linker table module support
  *
  * Modules can use linker tables, however the linker table definition
init/Kconfig +15 -0
index 536c2a00d972..6272f4fdcc86 100644
@@ -63,6 +63,28 @@ config CROSS_COMPILE
 	  need to set this unless you want the configured kernel build
 	  directory to select the cross-compiler automatically.
 
+config BUILD_AVOID_BITROT
+	bool "Enable force building of force-obj-y and force-lib-y"
+	default n
+	help
+	  When enabled objects under the force-obj-y and force-lib-y targets
+	  using a Kconfig symbol will be forced to compile if the Kconfig
+	  symbol's dependencies are met but only linked into the kernel if
+	  the Kconfig symbol is enabled. If a Kconfig symbol on a force-obj-y
+	  or force-lib-y target is disabled, it will be compiled but not linked
+	  into the kernel.
+
+	  The force-obj-y and force-lib-y targets can be used by subsystems
+	  which wish to want to follow the 'build-all selective-link philosophy'
+	  documented under include/linux/tables.h.
+

init/Kconfig config CROSS_COMPILE · line 90

Quoted 10 lines
init/Kconfig +7 -0
+	  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

Pleaase use COMPILE_TEST here, we've already marked almost all drivers with it today. We also have really good build tools, including cross compilers that you can use to test-build stuff on all different arches if you feel you are somehow not building things you need to test-build.

I fail to see how this is going to do anything different from what we have today, so why add it and have to maintain it? Have you enabled it on subsystems that currently do not get properly build tested and found any issues? What subsystems were they and why are they not in our current build tests?

thanks,

greg k-h

author maintainer
#145 lore raw

PATCH v7 6/14 firmware/Makefile: force recompilation if makefile changes

In reply to 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

---
 firmware/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
firmware/Makefile +2 -1
index e297e1b52636..fa3e81c2a97b 100644
@@ -176,7 +176,8 @@ quiet_cmd_fwbin = MK_FW   $@
 wordsize_deps := $(wildcard include/config/64bit.h include/config/32bit.h \
 		include/config/ppc32.h include/config/ppc64.h \
 		include/config/superh32.h include/config/superh64.h \
-		include/config/x86_32.h include/config/x86_64.h)
+		include/config/x86_32.h include/config/x86_64.h \
+		firmware/Makefile)
 
 $(patsubst %,$(obj)/%.gen.S, $(fw-shipped-y)): %: $(wordsize_deps)
 	$(call cmd,fwbin,$(patsubst %.gen.S,%,$@))
Signature · 1 line
2.11.0
maintainer
#146 lore raw

Re: [PATCH v7 06/14] firmware/Makefile: force recompilation if makefile changes

Quoted 18 lines · 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

---
 firmware/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
firmware/Makefile +0 -0
index e297e1b52636..fa3e81c2a97b 100644

firmware/Makefile quiet_cmd_fwbin = MK_FW $@ · line 183

Quoted 9 lines
firmware/Makefile +2 -1
@@ -176,7 +176,8 @@ quiet_cmd_fwbin = MK_FW   $@
 wordsize_deps := $(wildcard include/config/64bit.h include/config/32bit.h \
 		include/config/ppc32.h include/config/ppc64.h \
 		include/config/superh32.h include/config/superh64.h \
-		include/config/x86_32.h include/config/x86_64.h)
+		include/config/x86_32.h include/config/x86_64.h \
+		firmware/Makefile)
 
 $(patsubst %,$(obj)/%.gen.S, $(fw-shipped-y)): %: $(wordsize_deps)
 	$(call cmd,fwbin,$(patsubst %.gen.S,%,$@))

I don't understand why this patch is in this series :(

author maintainer
#147 lore raw

Re: [PATCH v7 06/14] firmware/Makefile: force recompilation if makefile changes

Quoted 26 lines · Greg KH
Quoted 25 lines · 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

---
 firmware/Makefile | 3 ++-
 1 file changed, 2 insertions(+), 1 deletion(-)
firmware/Makefile +2 -1
index e297e1b52636..fa3e81c2a97b 100644
@@ -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)
 
Quoted 4 lines

firmware/Makefile quiet_cmd_fwbin = MK_FW $@ · line 183

Quoted 2 lines
firmware/Makefile +0 -0
 $(patsubst %,$(obj)/%.gen.S, $(fw-shipped-y)): %: $(wordsize_deps)
 	$(call cmd,fwbin,$(patsubst %.gen.S,%,$@))

I don't understand why this patch is in this series :(

I've taken it out and it has now been routed via kbuild folks as you requested.

Thanks!

Luis

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author maintainer
#148 lore raw

PATCH v7 7/14 firmware: port built-in section to linker table

In reply to 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 linker table.

Tested with 0 built-in firmware, 1 and 2 built-in firmwares successfully.

v6: rename table macro as suggested by Andy Shevchenko

v5:

o since we dropped SECTION_ORDER_ANY, use 'any' order level explicitly

v4:

o work around c6x toolchain bug by using SECTION_TBL_RO

o fix compilation on blackfin

v3:
o explicitly include tables.h as we no longer include tables.h from sections.h

o use new section_tbl_asmtype() helper on firmware/Makefile to enable having to unfold things on our own.

v2: introduced this file in this version of the series

Cc Barry Song <[email protected]>
Cc Mike Frysinger <[email protected]>
Cc Steven Miao <[email protected]>
Cc Michael Matz <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Fengguang Wu <[email protected]>
---
 arch/x86/kernel/cpu/microcode/core.c |  8 ++++----
 drivers/base/firmware_class.c        | 12 ++++++------
 firmware/Makefile                    |  3 ++-
 include/asm-generic/vmlinux.lds.h    |  7 -------
 4 files changed, 12 insertions(+), 18 deletions(-)
arch/x86/kernel/cpu/microcode/core.c +4 -4
index 2af69d27da62..2c5004343b45 100644
@@ -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>
@@ -110,15 +111,14 @@ static bool __init check_loader_disabled_bsp(void)
 	return *res;
 }
 
-extern struct builtin_fw __start_builtin_fw[];
-extern struct builtin_fw __end_builtin_fw[];
+DECLARE_LINKTABLE_RO(struct builtin_fw, builtin_fw);
 
 bool get_builtin_firmware(struct cpio_data *cd, const char *name)
 {
 #ifdef CONFIG_FW_LOADER
-	struct builtin_fw *b_fw;
+	const struct builtin_fw *b_fw;
 
-	for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++) {
+	linktable_for_each(b_fw, builtin_fw) {
 		if (!strcmp(name, b_fw->name)) {
 			cd->size = b_fw->size;
 			cd->data = b_fw->data;
drivers/base/firmware_class.c +6 -6
index 4497d263209f..b9ac348e8d33 100644
@@ -31,6 +31,7 @@
 #include <linux/reboot.h>
 #include <linux/security.h>
 #include <linux/swait.h>
+#include <linux/tables.h>
 
 #include <generated/utsrelease.h>
 
@@ -44,15 +45,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;
@@ -68,9 +68,9 @@ static bool fw_get_builtin_firmware(struct firmware *fw, const char *name,
 
 static bool fw_is_builtin_firmware(const struct firmware *fw)
 {
-	struct builtin_fw *b_fw;
+	const struct builtin_fw *b_fw;
 
-	for (b_fw = __start_builtin_fw; b_fw != __end_builtin_fw; b_fw++)
+	linktable_for_each(b_fw, builtin_fw)
 		if (fw->data == b_fw->data)
 			return true;
 
firmware/Makefile +2 -1
index fa3e81c2a97b..9c8cae144ede 100644
@@ -155,6 +155,7 @@ quiet_cmd_fwbin = MK_FW   $@
 		  ASM_ALIGN=$(if $(CONFIG_64BIT),3,2);			     \
 		  PROGBITS=$(if $(CONFIG_ARM),%,@)progbits;		     \
 		  echo "/* Generated by firmware/Makefile */"		> $@;\
+		  echo "\#include <asm/tables.h>"			>>$@;\
 		  echo "    .section .rodata"				>>$@;\
 		  echo "    .p2align $${ASM_ALIGN}"			>>$@;\
 		  echo "_fw_$${FWSTR}_bin:"				>>$@;\
@@ -164,7 +165,7 @@ quiet_cmd_fwbin = MK_FW   $@
 		  echo "    .p2align $${ASM_ALIGN}"			>>$@;\
 		  echo "_fw_$${FWSTR}_name:"				>>$@;\
 		  echo "    .string \"$$FWNAME\""			>>$@;\
-		  echo "    .section .builtin_fw,\"a\",$${PROGBITS}"	>>$@;\
+		  echo "    set_section_tbl_type(SECTION_TBL_RO, builtin_fw, any, a,$${PROGBITS})" >>$@;\
 		  echo "    .p2align $${ASM_ALIGN}"			>>$@;\
 		  echo "    $${ASM_WORD} _fw_$${FWSTR}_name"		>>$@;\
 		  echo "    $${ASM_WORD} _fw_$${FWSTR}_bin"		>>$@;\
include/asm-generic/vmlinux.lds.h +0 -7
index ce1e9a310ada..8a5325d75932 100644
@@ -324,13 +324,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) = .;			\
-		KEEP(*(.builtin_fw))					\
-		VMLINUX_SYMBOL(__end_builtin_fw) = .;			\
-	}								\
-									\
 	TRACEDATA							\
 									\
 	/* Kernel symbol table: Normal symbols */			\
Signature · 1 line
2.11.0
author maintainer
#149 lore raw

PATCH v7 8/14 jump_label: move guard #endif down where it belongs

In reply to Luis R. Rodriguez

The ending header guard is misplaced. This has no
functional change, this is just an eye-sore.

---
 include/linux/jump_label.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/jump_label.h +2 -2
index a0547c571800..b63d6b7b0db0 100644
@@ -402,6 +402,6 @@ extern bool ____wrong_branch_error(void);
 #define static_branch_enable(x)		static_key_enable(&(x)->key)
 #define static_branch_disable(x)	static_key_disable(&(x)->key)
 
-#endif	/* _LINUX_JUMP_LABEL_H */
-
 #endif /* __ASSEMBLY__ */
+
+#endif	/* _LINUX_JUMP_LABEL_H */
Signature · 1 line
2.11.0
maintainer
#150 lore raw

Re: [PATCH v7 08/14] jump_label: move guard #endif down where it belongs

Quoted 23 lines · Luis R. Rodriguez

The ending header guard is misplaced. This has no
functional change, this is just an eye-sore.

---
 include/linux/jump_label.h | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)
include/linux/jump_label.h +2 -2
index a0547c571800..b63d6b7b0db0 100644
@@ -402,6 +402,6 @@ extern bool ____wrong_branch_error(void);
 #define static_branch_enable(x)		static_key_enable(&(x)->key)
 #define static_branch_disable(x)	static_key_disable(&(x)->key)
 
-#endif	/* _LINUX_JUMP_LABEL_H */
-
 #endif /* __ASSEMBLY__ */
+
+#endif	/* _LINUX_JUMP_LABEL_H */
Signature · 1 line
2.11.0

Why is this in this patch series?

author maintainer
#151 lore raw

PATCH v7 9/14 jump_label: port __jump_table to linker tables

In reply to 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 linker table and of the shared asm call push_section_tbl().

Built-in kernel functionality was tested with CONFIG_STATIC_KEYS_SELFTEST. Moduler kernel functionality was tested with CONFIG_TEST_STATIC_KEYS. Both work as expected.

Since __jump_table sections are also supported per module this also required expanding module-common.lds.S to capture and fold all .data.tlb.__jump_table.* onto the the section __jump_table -- in this case for modules need to keep a reference in place, given the alternative is to use DEFINE_LINKTABLE(struct jump_entry, __jump_table) per module -- and later through macro hacks instantiate the jump entries per module upon init. This is doable but we'd loose out on the sorting of the table using the linker, to sort we'd always still need to expand the module common linker script. An alternative mechanism is possible which would make these custom module sections extensions dynamic without requiring manual changes, this however is best done later through a separate evolution once linker tables are in place.

A careful reviewer may note that some architectures use "\n\t" to separate asm code, while others just use a new line. Upon review last time it was deemed reasonable to for all architectures to just use "\n", this is defined as ASM_CMD_SEP, and if an architecture needs to override they can do so on their architecture sections.h prior to including asm-generic/sections.h

v6: rename table macro as suggested by Andy Shevchenko

v5:

o Use ..tbl instead of .tbl as suggested by Nicholas Piggin. This is the typical way to avoid clash with compiler generated section.

o Replace section macros with section names

o Use LINKTABLE_START() and LINKTABLE_END()

o fixed tile jump label port -- tile got jump label support as of commit 65a792e84f25d1 ("tile/jump_label: add jump label support for TILE-Gx"), as such we just needed to adjust the asm to account for the new linker table API use. This commit was merged as of v4.5-rc1.

v4:

o Some architectures allow linker scripts to follow including header files, some others do not, so if you need a helper on a linker script you need to explicitly include it. So for instance although scripts/module-common.lds.S includes <asm/tables.h> and this file includes <asm/section-core.h>, you still need to explicitly include it on the linker script. This issue is present on ARM.

o as per Josh Poimboeuf open code the section table name instead of including the kernel section headers, the simplicity and independence from the kernel is preferred.

v3:

o More elaborate tests performed
o first modular support use case, module tested was CONFIG_TEST_STATIC_KEYS (lib/test_static_keys.ko), this required us to extend module-common.lds.S
o use generic push_section_tbl_any() for all architectures
o Makes use of ASM_CMD_SEP to enable architectures to override later if needed
o guard tables.h inclusion and table definition with __KERNEL__

v2: introduced in this series

---
 arch/arm/include/asm/jump_label.h     |  6 ++++--
 arch/arm64/include/asm/jump_label.h   |  6 ++++--
 arch/mips/include/asm/jump_label.h    |  6 ++++--
 arch/powerpc/include/asm/jump_label.h |  8 +++++---
 arch/s390/include/asm/jump_label.h    |  6 ++++--
 arch/sparc/include/asm/jump_label.h   |  6 ++++--
 arch/tile/include/asm/jump_label.h    |  5 +++--
 arch/x86/include/asm/jump_label.h     | 10 ++++++----
 include/asm-generic/vmlinux.lds.h     |  5 -----
 include/linux/jump_label.h            |  4 ++--
 kernel/jump_label.c                   | 17 ++++++++++-------
 scripts/module-common.lds             |  1 +
 tools/objtool/special.c               |  2 +-
 13 files changed, 48 insertions(+), 34 deletions(-)
arch/arm/include/asm/jump_label.h +4 -2
index 34f7b6980d21..609e0592a942 100644
@@ -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(.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(.data, __jump_table, aw)
 		 ".word 1b, %l[l_yes], %c0\n\t"
 		 ".popsection\n\t"
 		 : :  "i" (&((char *)key)[branch]) :  : l_yes);
arch/arm64/include/asm/jump_label.h +4 -2
index 1b5e0e843c3a..bb56ac4fafb5 100644
@@ -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(.data, __jump_table, aw)
 		 ".align 3\n\t"
 		 ".quad 1b, %l[l_yes], %c0\n\t"
 		 ".popsection\n\t"
@@ -43,7 +45,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran
 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(.data, __jump_table, aw)
 		 ".align 3\n\t"
 		 ".quad 1b, %l[l_yes], %c0\n\t"
 		 ".popsection\n\t"
arch/mips/include/asm/jump_label.h +4 -2
index e77672539e8e..07289a1b1bcd 100644
@@ -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(.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(.data, __jump_table, aw)
 		WORD_INSN " 1b, %l[l_yes], %0\n\t"
 		".popsection\n\t"
 		: :  "i" (&((char *)key)[branch]) : : l_yes);
arch/powerpc/include/asm/jump_label.h +5 -3
index 9a287e0ac8b1..7a75623740d0 100644
@@ -10,6 +10,8 @@
  * 2 of the License, or (at your option) any later version.
  */
 
+#include <asm/tables.h>
+
 #ifndef __ASSEMBLY__
 #include <linux/types.h>
 
@@ -23,7 +25,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran
 {
 	asm_volatile_goto("1:\n\t"
 		 "nop # arch_static_branch\n\t"
-		 ".pushsection __jump_table,  \"aw\"\n\t"
+		 push_section_tbl_any(.data, __jump_table, aw)
 		 JUMP_ENTRY_TYPE "1b, %l[l_yes], %c0\n\t"
 		 ".popsection \n\t"
 		 : :  "i" (&((char *)key)[branch]) : : l_yes);
@@ -37,7 +39,7 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool
 {
 	asm_volatile_goto("1:\n\t"
 		 "b %l[l_yes] # arch_static_branch_jump\n\t"
-		 ".pushsection __jump_table,  \"aw\"\n\t"
+		 push_section_tbl_any(.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(.data, __jump_table, aw); \
 	FTR_ENTRY_LONG 1098b, LABEL, KEY;	\
 	.popsection
 #endif
arch/s390/include/asm/jump_label.h +4 -2
index 9be198f5ee79..58e53af49e7e 100644
@@ -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(.data, __jump_table, aw)
 		".balign 8\n"
 		".quad 0b, %l[label], %0\n"
 		".popsection\n"
@@ -30,7 +32,7 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran
 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(.data, __jump_table, aw)
 		".balign 8\n"
 		".quad 0b, %l[label], %0\n"
 		".popsection\n"
arch/sparc/include/asm/jump_label.h +4 -2
index 62d0354d1727..35d3e5d31821 100644
@@ -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(.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(.data, __jump_table, aw)
 		 ".align 4\n\t"
 		 ".word 1b, %l[l_yes], %c0\n\t"
 		 ".popsection \n\t"
arch/tile/include/asm/jump_label.h +3 -2
index cde7573f397b..9bd989daad4a 100644
@@ -16,6 +16,7 @@
 #define _ASM_TILE_JUMP_LABEL_H
 
 #include <arch/opcode.h>
+#include <asm/tables.h>
 
 #define JUMP_LABEL_NOP_SIZE	TILE_BUNDLE_SIZE_IN_BYTES
 
@@ -24,7 +25,7 @@ static __always_inline bool arch_static_branch(struct static_key *key,
 {
 	asm_volatile_goto("1:\n\t"
 		"nop" "\n\t"
-		".pushsection __jump_table,  \"aw\"\n\t"
+		push_section_tbl_any(.data, __jump_table, aw)
 		".quad 1b, %l[l_yes], %0 + %1 \n\t"
 		".popsection\n\t"
 		: :  "i" (key), "i" (branch) : : l_yes);
@@ -38,7 +39,7 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key,
 {
 	asm_volatile_goto("1:\n\t"
 		"j %l[l_yes]" "\n\t"
-		".pushsection __jump_table,  \"aw\"\n\t"
+		push_section_tbl_any(.data, __jump_table, aw)
 		".quad 1b, %l[l_yes], %0 + %1 \n\t"
 		".popsection\n\t"
 		: :  "i" (key), "i" (branch) : : l_yes);
arch/x86/include/asm/jump_label.h +6 -4
index adc54c12cbd1..627df4752db0 100644
@@ -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(.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(.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(.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(.data, __jump_table, aw)
 	_ASM_ALIGN
 	_ASM_PTR	.Lstatic_jump_\@, \target, \key + 1
 	.popsection
include/asm-generic/vmlinux.lds.h +0 -5
index 8a5325d75932..887d844f0406 100644
@@ -216,11 +216,6 @@
 	*(.data.unlikely)						\
 	STRUCT_ALIGN();							\
 	*(__tracepoints)						\
-	/* implement dynamic printk debug */				\
-	. = ALIGN(8);                                                   \
-	VMLINUX_SYMBOL(__start___jump_table) = .;                       \
-	KEEP(*(__jump_table))                                           \
-	VMLINUX_SYMBOL(__stop___jump_table) = .;                        \
 	. = ALIGN(8);							\
 	VMLINUX_SYMBOL(__start___verbose) = .;                          \
 	KEEP(*(__verbose))                                              \
include/linux/jump_label.h +2 -2
index b63d6b7b0db0..e6277888b558 100644
@@ -117,6 +117,7 @@ enum jump_label_type {
 struct module;
 
 #ifdef HAVE_JUMP_LABEL
+#include <linux/tables.h>
 
 #define JUMP_TYPE_FALSE	0UL
 #define JUMP_TYPE_TRUE	1UL
@@ -132,8 +133,7 @@ static __always_inline bool static_key_true(struct static_key *key)
 	return !arch_static_branch(key, true);
 }
 
-extern struct jump_entry __start___jump_table[];
-extern struct jump_entry __stop___jump_table[];
+DECLARE_LINKTABLE(struct jump_entry, __jump_table);
 
 extern void jump_label_init(void);
 extern void jump_label_lock(void);
kernel/jump_label.c +10 -7
index 93ad6c1fb9b6..4252f17eaeb5 100644
@@ -15,9 +15,12 @@
 #include <linux/static_key.h>
 #include <linux/jump_label_ratelimit.h>
 #include <linux/bug.h>
+#include <linux/tables.h>
 
 #ifdef HAVE_JUMP_LABEL
 
+DEFINE_LINKTABLE(struct jump_entry, __jump_table);
+
 /* mutex to protect coming/going of the the jump_label table */
 static DEFINE_MUTEX(jump_label_mutex);
 
@@ -274,8 +277,6 @@ static void __jump_label_update(struct static_key *key,
 
 void __init jump_label_init(void)
 {
-	struct jump_entry *iter_start = __start___jump_table;
-	struct jump_entry *iter_stop = __stop___jump_table;
 	struct static_key *key = NULL;
 	struct jump_entry *iter;
 
@@ -292,9 +293,10 @@ void __init jump_label_init(void)
 		return;
 
 	jump_label_lock();
-	jump_label_sort_entries(iter_start, iter_stop);
+	jump_label_sort_entries(LINKTABLE_START(__jump_table),
+				LINKTABLE_END(__jump_table));
 
-	for (iter = iter_start; iter < iter_stop; iter++) {
+	linktable_for_each(iter, __jump_table) {
 		struct static_key *iterk;
 
 		/* rewrite NOPs */
@@ -539,8 +541,9 @@ early_initcall(jump_label_init_module);
  */
 int jump_label_text_reserved(void *start, void *end)
 {
-	int ret = __jump_label_text_reserved(__start___jump_table,
-			__stop___jump_table, start, end);
+	int ret = __jump_label_text_reserved(LINKTABLE_START(__jump_table),
+					     LINKTABLE_END(__jump_table),
+					     start, end);
 
 	if (ret)
 		return ret;
@@ -553,7 +556,7 @@ int jump_label_text_reserved(void *start, void *end)
 
 static void jump_label_update(struct static_key *key)
 {
-	struct jump_entry *stop = __stop___jump_table;
+	struct jump_entry *stop = LINKTABLE_END(__jump_table);
 	struct jump_entry *entry = static_key_entries(key);
 #ifdef CONFIG_MODULES
 	struct module *mod;
scripts/module-common.lds +1 -0
index 73a2c7da0e55..db0e724556c5 100644
@@ -16,6 +16,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(.data..tbl.__jump_table.*)) }
 
 	. = ALIGN(8);
 	.init_array		0 : { *(SORT(.init_array.*)) *(.init_array) }
tools/objtool/special.c +1 -1
index bff8abb3a4aa..79968e118294 100644
@@ -63,7 +63,7 @@ struct special_entry entries[] = {
 		.feature = ALT_FEATURE_OFFSET,
 	},
 	{
-		.sec = "__jump_table",
+		.sec = ".data..tbl.__jump_table.any",
 		.jump_or_nop = true,
 		.size = JUMP_ENTRY_SIZE,
 		.orig = JUMP_ORIG_OFFSET,
Signature · 1 line
2.11.0
maintainer
#152 lore raw

Re: [PATCH v7 09/14] jump_label: port __jump_table to linker tables

Quoted 78 lines · 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 linker table and of the shared asm call push_section_tbl().

Built-in kernel functionality was tested with CONFIG_STATIC_KEYS_SELFTEST. Moduler kernel functionality was tested with CONFIG_TEST_STATIC_KEYS. Both work as expected.

Since __jump_table sections are also supported per module this also required expanding module-common.lds.S to capture and fold all .data.tlb.__jump_table.* onto the the section __jump_table -- in this case for modules need to keep a reference in place, given the alternative is to use DEFINE_LINKTABLE(struct jump_entry, __jump_table) per module -- and later through macro hacks instantiate the jump entries per module upon init. This is doable but we'd loose out on the sorting of the table using the linker, to sort we'd always still need to expand the module common linker script. An alternative mechanism is possible which would make these custom module sections extensions dynamic without requiring manual changes, this however is best done later through a separate evolution once linker tables are in place.

A careful reviewer may note that some architectures use "\n\t" to separate asm code, while others just use a new line. Upon review last time it was deemed reasonable to for all architectures to just use "\n", this is defined as ASM_CMD_SEP, and if an architecture needs to override they can do so on their architecture sections.h prior to including asm-generic/sections.h

v6: rename table macro as suggested by Andy Shevchenko

v5:

o Use ..tbl instead of .tbl as suggested by Nicholas Piggin. This is the typical way to avoid clash with compiler generated section.

o Replace section macros with section names

o Use LINKTABLE_START() and LINKTABLE_END()

o fixed tile jump label port -- tile got jump label support as of commit 65a792e84f25d1 ("tile/jump_label: add jump label support for TILE-Gx"), as such we just needed to adjust the asm to account for the new linker table API use. This commit was merged as of v4.5-rc1.

v4:

o Some architectures allow linker scripts to follow including header files, some others do not, so if you need a helper on a linker script you need to explicitly include it. So for instance although scripts/module-common.lds.S includes <asm/tables.h> and this file includes <asm/section-core.h>, you still need to explicitly include it on the linker script. This issue is present on ARM.

o as per Josh Poimboeuf open code the section table name instead of including the kernel section headers, the simplicity and independence from the kernel is preferred.

v3:

o More elaborate tests performed
o first modular support use case, module tested was CONFIG_TEST_STATIC_KEYS (lib/test_static_keys.ko), this required us to extend module-common.lds.S
o use generic push_section_tbl_any() for all architectures
o Makes use of ASM_CMD_SEP to enable architectures to override later if needed
o guard tables.h inclusion and table definition with __KERNEL__

v2: introduced in this series

Quoted 15 lines
---
 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/tile/include/asm/jump_label.h    |  5 +++--
 arch/x86/include/asm/jump_label.h     | 10 ++++++----
 include/asm-generic/vmlinux.lds.h     |  5 -----
 include/linux/jump_label.h            |  4 ++--
 kernel/jump_label.c                   | 17 ++++++++++-------
 scripts/module-common.lds             |  1 +
 tools/objtool/special.c               |  2 +-
 13 files changed, 48 insertions(+), 34 deletions(-)

meta-comment. This new infrastructure doesn't seem to save any code when you need to have a new "link table". Yes, the macros seem a bit nicer, but it feels like unneeded churn. I haven't seen any patches in this series that makes me go "oh yeah, now I see why he did this work, it's so much simpler and easy to understand now!"

What am I missing? What wonderful new things are going to happen, or where is the code savings going to come from with this series to justify all of the work to create and review this?

thanks,

greg k-h

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel

author maintainer
#153 lore raw

PATCH v7 10/14 dynamic_debug: port to use linker tables

In reply to Luis R. Rodriguez

This removes the custom vmlinux.lds.h hacks and uses the generalized solution for .data entries.

There is much more potential for further fine tuning here in the future though. 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. We can work on this later to make this change easier to review.

Tested dynamic debug with dyndbg query and debugfs control and it works as expected, for both built-in code and modules.

v6: rename table macro as suggested by Andy Shevchenko

v5:

o Use ..tbl instead of .tbl as suggested by Nicholas Piggin. This is the typical way to avoid clash with compiler generated section.

o Replace section macros with section names,
use LINKTABLE_EMPTY(), LINKTABLE_START()

v4: fix compilation on blackfin
v3: added modular support
v2: introduced this patch into the series

Cc Barry Song <[email protected]>
Cc Mike Frysinger <[email protected]>
Cc Steven Miao <[email protected]>
Cc Michael Matz <[email protected]>
Cc Guenter Roeck <[email protected]>
Cc Fengguang Wu <[email protected]>
---
 include/asm-generic/vmlinux.lds.h |  4 ----
 include/linux/dynamic_debug.h     |  5 +++--
 lib/dynamic_debug.c               | 13 ++++++-------
 scripts/module-common.lds         |  1 +
 4 files changed, 10 insertions(+), 13 deletions(-)
include/asm-generic/vmlinux.lds.h +0 -4
index 887d844f0406..37b99537d5a9 100644
@@ -216,10 +216,6 @@
 	*(.data.unlikely)						\
 	STRUCT_ALIGN();							\
 	*(__tracepoints)						\
-	. = ALIGN(8);							\
-	VMLINUX_SYMBOL(__start___verbose) = .;                          \
-	KEEP(*(__verbose))                                              \
-	VMLINUX_SYMBOL(__stop___verbose) = .;				\
 	LIKELY_PROFILE()		       				\
 	BRANCH_PROFILE()						\
 	TRACE_PRINTKS()							\
include/linux/dynamic_debug.h +3 -2
index 546d68057e3b..a52618a77b09 100644
@@ -4,6 +4,7 @@
 #if defined(CC_HAVE_ASM_GOTO) && defined(CONFIG_JUMP_LABEL)
 #include <linux/jump_label.h>
 #endif
+#include <linux/tables.h>
 
 /*
  * An instance of this structure is created in a special
@@ -50,6 +51,7 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n,
 				const char *modname);
 
 #if defined(CONFIG_DYNAMIC_DEBUG)
+DECLARE_LINKTABLE(struct _ddebug, __verbose);
 extern int ddebug_remove_module(const char *mod_name);
 extern __printf(2, 3)
 void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...);
@@ -71,8 +73,7 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor,
 			  const char *fmt, ...);
 
 #define DEFINE_DYNAMIC_DEBUG_METADATA_KEY(name, fmt, key, init)	\
-	static struct _ddebug  __aligned(8)			\
-	__attribute__((section("__verbose"))) name = {		\
+	static LINKTABLE(__verbose, SECTION_ORDER_ANY) name = {	\
 		.modname = KBUILD_MODNAME,			\
 		.function = __func__,				\
 		.filename = __FILE__,				\
lib/dynamic_debug.c +6 -7
index da796e2dc4f5..27a335e3b1f3 100644
@@ -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 (LINKTABLE_EMPTY(__verbose)) {
+		pr_warn("dynamic debug linker table empty on CONFIG_DYNAMIC_DEBUG build\n");
 		return 1;
 	}
-	iter = __start___verbose;
+	iter = LINKTABLE_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)(LINKTABLE_SIZE(__verbose)));
 
 	/* apply ddebug_query boot param, dont unload tables on err */
 	if (ddebug_setup_string[0] != '\0') {
scripts/module-common.lds +1 -0
index db0e724556c5..25755d458f09 100644
@@ -17,6 +17,7 @@ SECTIONS {
 	__kcrctab_unused_gpl	0 : { *(SORT(___kcrctab_unused_gpl+*)) }
 	__kcrctab_gpl_future	0 : { *(SORT(___kcrctab_gpl_future+*)) }
 	__jump_table		0 : { *(SORT(.data..tbl.__jump_table.*)) }
+	__verbose		0 : { *(SORT(.data..tbl.__verbose.*)) }
 
 	. = ALIGN(8);
 	.init_array		0 : { *(SORT(.init_array.*)) *(.init_array) }
Signature · 1 line
2.11.0
author maintainer
#154 lore raw

PATCH v7 11/14 kprobes: move kprobe declarations to asm-generic/kprobes.h

In reply to Luis R. Rodriguez

Often all is needed is these small helpers, instead of compiler.h or a full kprobes.h. This is important for asm helpers, in fact even some asm/kprobes.h make use of these helpers... instead just keep a generic asm file with helpers useful for asm code with the least amount of clutter as possible.

Likewise we need now to also address what to do about this file for both when architectures have CONFIG_HAVE_KPROBES, and when they do not. Then for when architectures have CONFIG_HAVE_KPROBES but have disabled CONFIG_KPROBES.

Right now most asm/kprobes.h do not have guards against CONFIG_KPROBES, this means most architecture code cannot include asm/kprobes.h safely. Correct this and add guards for architectures missing them. Additionally provide architectures that not have kprobes support with the default asm-generic solution. This lets us force asm/kprobes.h on the header include/linux/kprobes.h always, but most importantly we can now safely include just asm/kprobes.h on architecture code without bringing the full kitchen sink of header files.

Two architectures already provided a guard against CONFIG_KPROBES on its kprobes.h: sh, arch. The rest of the architectures needed gaurds added. We avoid including any not-needed headers on asm/kprobes.h unless kprobes have been enabled.

In a subsequent atomic change we can try now to remove compiler.h from include/linux/kprobes.h.

During this sweep I've also identified a few architectures defining a common macro needed for both kprobes and ftrace, that of the definition of the breakput instruction up. Some refer to this as BREAKPOINT_INSTRUCTION. This must be kept outside of the #ifdef CONFIG_KPROBES guard.

v5:

o fix BREAKPOINT_INSTRUCTION dependency with kernel architecture ftrace implementations: Although its correct to #ifdef CONFIG_KPROBES on the architecture arch/$(ARCH)/include/asm/kprobes.h when architectures support ftrace they will rely on the BREAKPOINT_INSTRUCTION definition, this needs to be kept out from CONFIG_KPROBES as ftrace can be enabled without kprobes. This fixes compilation on x86 where kprobes is disabled but ftrace is left enabled.

o include <asm/kprobes.h> on arch/arm64/kernel/probes/decode-insn.h

v4: introduced this patch into the series

---
 MAINTAINERS                            |  1 +
 arch/alpha/include/asm/Kbuild          |  1 +
 arch/arc/include/asm/kprobes.h         |  6 ++++--
 arch/arm/include/asm/kprobes.h         |  4 ++++
 arch/arm/probes/decode.h               |  1 +
 arch/arm64/include/asm/kprobes.h       |  4 ++++
 arch/arm64/kernel/insn.c               |  1 +
 arch/arm64/kernel/probes/decode-insn.h |  2 ++
 arch/avr32/include/asm/kprobes.h       |  7 ++++++-
 arch/blackfin/include/asm/Kbuild       |  1 +
 arch/c6x/include/asm/Kbuild            |  1 +
 arch/cris/include/asm/Kbuild           |  1 +
 arch/frv/include/asm/Kbuild            |  1 +
 arch/h8300/include/asm/Kbuild          |  1 +
 arch/hexagon/include/asm/Kbuild        |  1 +
 arch/ia64/include/asm/kprobes.h        | 12 +++++++++---
 arch/m32r/include/asm/Kbuild           |  1 +
 arch/m68k/include/asm/Kbuild           |  1 +
 arch/metag/include/asm/Kbuild          |  1 +
 arch/microblaze/include/asm/Kbuild     |  1 +
 arch/mips/include/asm/kprobes.h        |  6 +++++-
 arch/mn10300/include/asm/kprobes.h     |  7 ++++++-
 arch/nios2/include/asm/Kbuild          |  1 +
 arch/openrisc/include/asm/Kbuild       |  1 +
 arch/parisc/include/asm/Kbuild         |  1 +
 arch/powerpc/include/asm/kprobes.h     |  3 +++
 arch/s390/include/asm/kprobes.h        |  7 ++++++-
 arch/score/include/asm/Kbuild          |  1 +
 arch/sh/include/asm/kprobes.h          |  5 ++++-
 arch/sparc/include/asm/kprobes.h       | 10 ++++++++--
 arch/tile/include/asm/kprobes.h        |  6 +++++-
 arch/um/include/asm/Kbuild             |  1 +
 arch/unicore32/include/asm/Kbuild      |  1 +
 arch/x86/include/asm/kprobes.h         |  9 ++++++++-
 arch/xtensa/include/asm/Kbuild         |  1 +
 include/asm-generic/kprobes.h          | 25 +++++++++++++++++++++++++
 include/linux/compiler.h               |  8 --------
 include/linux/kprobes.h                | 19 +++----------------
 38 files changed, 123 insertions(+), 38 deletions(-)
 create mode 100644 include/asm-generic/kprobes.h
MAINTAINERS +1 -0
index 99ca436e76d9..cee1efd50e04 100644
@@ -7250,6 +7250,7 @@ M:	Masami Hiramatsu <[email protected]>
 S:	Maintained
 F:	Documentation/kprobes.txt
 F:	include/linux/kprobes.h
+F:	include/asm-generic/kprobes.h
 F:	kernel/kprobes.c
 
 KS0108 LCD CONTROLLER DRIVER
arch/alpha/include/asm/Kbuild +1 -0
index f3bdc31d3c97..54d388fd026f 100644
@@ -13,3 +13,4 @@ generic-y += trace_clock.h
 generic-y += section-core.h
 generic-y += ranges.h
 generic-y += tables.h
+generic-y += kprobes.h
arch/arc/include/asm/kprobes.h +4 -2
index 944dbedb38b5..00bdbe167615 100644
@@ -9,6 +9,8 @@
 #ifndef _ARC_KPROBES_H
 #define _ARC_KPROBES_H
 
+#include <asm-generic/kprobes.h>
+
 #ifdef CONFIG_KPROBES
 
 typedef u16 kprobe_opcode_t;
@@ -55,6 +57,6 @@ void trap_is_kprobe(unsigned long address, struct pt_regs *regs);
 static void trap_is_kprobe(unsigned long address, struct pt_regs *regs)
 {
 }
-#endif
+#endif /* CONFIG_KPROBES */
 
-#endif
+#endif /* _ARC_KPROBES_H */
arch/arm/include/asm/kprobes.h +4 -0
index 3ea9be559726..59655459da59 100644
@@ -16,6 +16,9 @@
 #ifndef _ARM_KPROBES_H
 #define _ARM_KPROBES_H
 
+#include <asm-generic/kprobes.h>
+
+#ifdef CONFIG_KPROBES
 #include <linux/types.h>
 #include <linux/ptrace.h>
 #include <linux/notifier.h>
@@ -83,4 +86,5 @@ struct arch_optimized_insn {
 	 */
 };
 
+#endif /* CONFIG_KPROBES */
 #endif /* _ARM_KPROBES_H */
arch/arm/probes/decode.h +1 -0
index f9b08ba7fe73..548d622a3159 100644
@@ -22,6 +22,7 @@
 #include <linux/types.h>
 #include <linux/stddef.h>
 #include <asm/probes.h>
+#include <asm/kprobes.h>
 
 void __init arm_probes_decode_init(void);
 
arch/arm64/include/asm/kprobes.h +4 -0
index 1737aecfcc5e..6deb8d726041 100644
@@ -16,6 +16,9 @@
 #ifndef _ARM_KPROBES_H
 #define _ARM_KPROBES_H
 
+#include <asm-generic/kprobes.h>
+
+#ifdef CONFIG_KPROBES
 #include <linux/types.h>
 #include <linux/ptrace.h>
 #include <linux/percpu.h>
@@ -57,4 +60,5 @@ int kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr);
 void kretprobe_trampoline(void);
 void __kprobes *trampoline_probe_handler(struct pt_regs *regs);
 
+#endif /* CONFIG_KPROBES */
 #endif /* _ARM_KPROBES_H */
arch/arm64/kernel/insn.c +1 -0
index 022d4a9d1738..4e02fd369bf9 100644
@@ -31,6 +31,7 @@
 #include <asm/debug-monitors.h>
 #include <asm/fixmap.h>
 #include <asm/insn.h>
+#include <asm/kprobes.h>
 
 #define AARCH64_INSN_SF_BIT	BIT(31)
 #define AARCH64_INSN_N_BIT	BIT(22)
arch/arm64/kernel/probes/decode-insn.h +2 -0
index 76d3f315407f..192ab007bacb 100644
@@ -16,6 +16,8 @@
 #ifndef _ARM_KERNEL_KPROBES_ARM64_H
 #define _ARM_KERNEL_KPROBES_ARM64_H
 
+#include <asm/kprobes.h>
+
 /*
  * ARM strongly recommends a limit of 128 bytes between LoadExcl and
  * StoreExcl instructions in a single thread of execution. So keep the
arch/avr32/include/asm/kprobes.h +6 -1
index 45f563ed73fd..28dfc61ad384 100644
@@ -11,10 +11,14 @@
 #ifndef __ASM_AVR32_KPROBES_H
 #define __ASM_AVR32_KPROBES_H
 
+#include <asm-generic/kprobes.h>
+
+#define BREAKPOINT_INSTRUCTION	0xd673	/* breakpoint */
+
+#ifdef CONFIG_KPROBES
 #include <linux/types.h>
 
 typedef u16	kprobe_opcode_t;
-#define BREAKPOINT_INSTRUCTION	0xd673	/* breakpoint */
 #define MAX_INSN_SIZE		2
 #define MAX_STACK_SIZE		64	/* 32 would probably be OK */
 
@@ -46,4 +50,5 @@ extern int kprobe_exceptions_notify(struct notifier_block *self,
 
 #define flush_insn_slot(p)	do { } while (0)
 
+#endif /* CONFIG_KPROBES */
 #endif /* __ASM_AVR32_KPROBES_H */
arch/blackfin/include/asm/Kbuild +1 -0
index 9115b215fc7e..52351d3fd36e 100644
@@ -50,3 +50,4 @@ generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
 generic-y += tables.h
+generic-y += kprobes.h
arch/c6x/include/asm/Kbuild +1 -0
index cede2a950fbf..c54f7cc1f63e 100644
@@ -64,3 +64,4 @@ generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += kprobes.h
arch/cris/include/asm/Kbuild +1 -0
index 7062c1be7913..051d355feae3 100644
@@ -48,3 +48,4 @@ generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
 generic-y += tables.h
+generic-y += kprobes.h
arch/frv/include/asm/Kbuild +1 -0
index 4a59cbda5091..b58b9fc49383 100644
@@ -11,3 +11,4 @@ generic-y += word-at-a-time.h
 generic-y += section-core.h
 generic-y += ranges.h
 generic-y += tables.h
+generic-y += kprobes.h
arch/h8300/include/asm/Kbuild +1 -0
index d79968d93c12..cfca7de52b37 100644
@@ -78,3 +78,4 @@ generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
 generic-y += tables.h
+generic-y += kprobes.h
arch/hexagon/include/asm/Kbuild +1 -0
index d59ac1c1858b..d7cc35451f30 100644
@@ -63,3 +63,4 @@ generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
 generic-y += tables.h
+generic-y += kprobes.h
arch/ia64/include/asm/kprobes.h +9 -3
index d5505d6f2382..0302b3664789 100644
@@ -23,14 +23,19 @@
  * 2005-Apr     Rusty Lynch <[email protected]> and Anil S Keshavamurthy
  *              <[email protected]> adapted from i386
  */
+#include <asm-generic/kprobes.h>
+#include <asm/break.h>
+
+#define BREAK_INST	(long)(__IA64_BREAK_KPROBE << 6)
+
+#ifdef CONFIG_KPROBES
+
 #include <linux/types.h>
 #include <linux/ptrace.h>
 #include <linux/percpu.h>
-#include <asm/break.h>
 
 #define __ARCH_WANT_KPROBES_INSN_SLOT
 #define MAX_INSN_SIZE   2	/* last half is for kprobe-booster */
-#define BREAK_INST	(long)(__IA64_BREAK_KPROBE << 6)
 #define NOP_M_INST	(long)(1<<27)
 #define BRL_INST(i1, i2) ((long)((0xcL << 37) |	/* brl */ \
 				(0x1L << 12) |	/* many */ \
@@ -124,4 +129,5 @@ extern void invalidate_stacked_regs(void);
 extern void flush_register_stack(void);
 extern void arch_remove_kprobe(struct kprobe *p);
 
-#endif				/* _ASM_KPROBES_H */
+#endif /* CONFIG_KPROBES */
+#endif /* _ASM_KPROBES_H */
arch/m32r/include/asm/Kbuild +1 -0
index f3f1e51dd5be..60024b49b6bb 100644
@@ -15,3 +15,4 @@ generic-y += word-at-a-time.h
 generic-y += section-core.h
 generic-y += ranges.h
 generic-y += tables.h
+generic-y += kprobes.h
arch/m68k/include/asm/Kbuild +1 -0
index c28bcdecc764..412dd23ab946 100644
@@ -37,3 +37,4 @@ generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
 generic-y += tables.h
+generic-y += kprobes.h
arch/metag/include/asm/Kbuild +1 -0
index c836f7e2a5e7..8371cc9b1b3c 100644
@@ -58,3 +58,4 @@ generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
 generic-y += tables.h
+generic-y += kprobes.h
arch/microblaze/include/asm/Kbuild +1 -0
index 01afb1b420f5..865ce3d96443 100644
@@ -14,3 +14,4 @@ generic-y += word-at-a-time.h
 generic-y += section-core.h
 generic-y += ranges.h
 generic-y += tables.h
+generic-y += kprobes.h
arch/mips/include/asm/kprobes.h +5 -1
index daba1f9a4f79..291846d9ba83 100644
@@ -22,6 +22,9 @@
 #ifndef _ASM_KPROBES_H
 #define _ASM_KPROBES_H
 
+#include <asm-generic/kprobes.h>
+
+#ifdef CONFIG_KPROBES
 #include <linux/ptrace.h>
 #include <linux/types.h>
 
@@ -94,4 +97,5 @@ struct kprobe_ctlblk {
 extern int kprobe_exceptions_notify(struct notifier_block *self,
 				    unsigned long val, void *data);
 
-#endif				/* _ASM_KPROBES_H */
+#endif /* CONFIG_KPROBES */
+#endif /* _ASM_KPROBES_H */
arch/mn10300/include/asm/kprobes.h +6 -1
index c800b590183a..7abea0bdb549 100644
@@ -21,13 +21,17 @@
 #ifndef _ASM_KPROBES_H
 #define _ASM_KPROBES_H
 
+#include <asm-generic/kprobes.h>
+
+#define BREAKPOINT_INSTRUCTION	0xff
+
+#ifdef CONFIG_KPROBES
 #include <linux/types.h>
 #include <linux/ptrace.h>
 
 struct kprobe;
 
 typedef unsigned char kprobe_opcode_t;
-#define BREAKPOINT_INSTRUCTION	0xff
 #define MAX_INSN_SIZE 8
 #define MAX_STACK_SIZE 128
 
@@ -47,4 +51,5 @@ extern int kprobe_exceptions_notify(struct notifier_block *self,
 
 extern void arch_remove_kprobe(struct kprobe *p);
 
+#endif /* CONFIG_KPROBES */
 #endif /* _ASM_KPROBES_H */
arch/nios2/include/asm/Kbuild +1 -0
index ee6220dac1e8..d6ce7edee7e0 100644
@@ -66,3 +66,4 @@ generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
 generic-y += tables.h
+generic-y += kprobes.h
arch/openrisc/include/asm/Kbuild +1 -0
index ceafe458e295..1bf89a67317c 100644
@@ -74,3 +74,4 @@ generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
 generic-y += tables.h
+generic-y += kprobes.h
arch/parisc/include/asm/Kbuild +1 -0
index aaae8a9f6099..19d5b7e12ecf 100644
@@ -31,3 +31,4 @@ generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
 generic-y += tables.h
+generic-y += kprobes.h
arch/powerpc/include/asm/kprobes.h +3 -0
index 97b8c1f83453..c7ee3fcbd6e2 100644
@@ -1,5 +1,8 @@
 #ifndef _ASM_POWERPC_KPROBES_H
 #define _ASM_POWERPC_KPROBES_H
+
+#include <asm-generic/kprobes.h>
+
 #ifdef __KERNEL__
 /*
  *  Kernel Probes (KProbes)
arch/s390/include/asm/kprobes.h +6 -1
index 591e5a5279b0..84c0f9086483 100644
@@ -27,6 +27,11 @@
  * 2005-Dec	Used as a template for s390 by Mike Grundy
  *		<[email protected]>
  */
+#include <asm-generic/kprobes.h>
+
+#define BREAKPOINT_INSTRUCTION	0x0002
+
+#ifdef CONFIG_KPROBES
 #include <linux/types.h>
 #include <linux/ptrace.h>
 #include <linux/percpu.h>
@@ -37,7 +42,6 @@ struct pt_regs;
 struct kprobe;
 
 typedef u16 kprobe_opcode_t;
-#define BREAKPOINT_INSTRUCTION	0x0002
 
 /* Maximum instruction size is 3 (16bit) halfwords: */
 #define MAX_INSN_SIZE		0x0003
@@ -91,4 +95,5 @@ int probe_is_insn_relative_long(u16 *insn);
 
 #define flush_insn_slot(p)	do { } while (0)
 
+#endif /* CONFIG_KPROBES */
 #endif	/* _ASM_S390_KPROBES_H */
arch/score/include/asm/Kbuild +1 -0
index 16ea15a3e432..6ac8a7f5c768 100644
@@ -17,3 +17,4 @@ generic-y += word-at-a-time.h
 generic-y += section-core.h
 generic-y += ranges.h
 generic-y += tables.h
+generic-y += kprobes.h
arch/sh/include/asm/kprobes.h +4 -1
index 134f3980e44a..f0986f9b3844 100644
@@ -1,13 +1,16 @@
 #ifndef __ASM_SH_KPROBES_H
 #define __ASM_SH_KPROBES_H
 
+#include <asm-generic/kprobes.h>
+
+#define BREAKPOINT_INSTRUCTION	0xc33a
+
 #ifdef CONFIG_KPROBES
 
 #include <linux/types.h>
 #include <linux/ptrace.h>
 
 typedef insn_size_t kprobe_opcode_t;
-#define BREAKPOINT_INSTRUCTION	0xc33a
 
 #define MAX_INSN_SIZE 16
 #define MAX_STACK_SIZE 64
arch/sparc/include/asm/kprobes.h +8 -2
index a145d798e112..49f8402035d7 100644
@@ -1,13 +1,17 @@
 #ifndef _SPARC64_KPROBES_H
 #define _SPARC64_KPROBES_H
 
+#include <asm-generic/kprobes.h>
+
+#define BREAKPOINT_INSTRUCTION   0x91d02070 /* ta 0x70 */
+#define BREAKPOINT_INSTRUCTION_2 0x91d02071 /* ta 0x71 */
+
+#ifdef CONFIG_KPROBES
 #include <linux/types.h>
 #include <linux/percpu.h>
 
 typedef u32 kprobe_opcode_t;
 
-#define BREAKPOINT_INSTRUCTION   0x91d02070 /* ta 0x70 */
-#define BREAKPOINT_INSTRUCTION_2 0x91d02071 /* ta 0x71 */
 #define MAX_INSN_SIZE 2
 
 #define kretprobe_blacklist_size 0
@@ -48,4 +52,6 @@ int kprobe_exceptions_notify(struct notifier_block *self,
 int kprobe_fault_handler(struct pt_regs *regs, int trapnr);
 asmlinkage void __kprobes kprobe_trap(unsigned long trap_level,
 				      struct pt_regs *regs);
+
+#endif /* CONFIG_KPROBES */
 #endif /* _SPARC64_KPROBES_H */
arch/tile/include/asm/kprobes.h +5 -1
index d8f9a83943b1..4a8b1cadca24 100644
@@ -17,10 +17,13 @@
 #ifndef _ASM_TILE_KPROBES_H
 #define _ASM_TILE_KPROBES_H
 
+#include <asm-generic/kprobes.h>
+
+#ifdef CONFIG_KPROBES
+
 #include <linux/types.h>
 #include <linux/ptrace.h>
 #include <linux/percpu.h>
-
 #include <arch/opcode.h>
 
 #define __ARCH_WANT_KPROBES_INSN_SLOT
@@ -76,4 +79,5 @@ void arch_remove_kprobe(struct kprobe *);
 extern int kprobe_exceptions_notify(struct notifier_block *self,
 			     unsigned long val, void *data);
 
+#endif /* CONFIG_KPROBES */
 #endif /* _ASM_TILE_KPROBES_H */
arch/um/include/asm/Kbuild +1 -0
index d2867aa09e23..ccc5ffeaeef5 100644
@@ -29,3 +29,4 @@ generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
 generic-y += tables.h
+generic-y += kprobes.h
arch/unicore32/include/asm/Kbuild +1 -0
index 6671a1f08ead..5aacafb6d385 100644
@@ -63,3 +63,4 @@ generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += ranges.h
 generic-y += tables.h
+generic-y += kprobes.h
arch/x86/include/asm/kprobes.h +8 -1
index d1d1e5094c28..200581691c6e 100644
@@ -21,6 +21,12 @@
  *
  * See arch/x86/kernel/kprobes.c for x86 kprobes history.
  */
+
+#include <asm-generic/kprobes.h>
+
+#define BREAKPOINT_INSTRUCTION	0xcc
+
+#ifdef CONFIG_KPROBES
 #include <linux/types.h>
 #include <linux/ptrace.h>
 #include <linux/percpu.h>
@@ -32,7 +38,6 @@ struct pt_regs;
 struct kprobe;
 
 typedef u8 kprobe_opcode_t;
-#define BREAKPOINT_INSTRUCTION	0xcc
 #define RELATIVEJUMP_OPCODE 0xe9
 #define RELATIVEJUMP_SIZE 5
 #define RELATIVECALL_OPCODE 0xe8
@@ -116,4 +121,6 @@ extern int kprobe_exceptions_notify(struct notifier_block *self,
 				    unsigned long val, void *data);
 extern int kprobe_int3_handler(struct pt_regs *regs);
 extern int kprobe_debug_handler(struct pt_regs *regs);
+
+#endif /* CONFIG_KPROBES */
 #endif /* _ASM_X86_KPROBES_H */
arch/xtensa/include/asm/Kbuild +1 -0
index 7b41f32a2ba0..20f524ded00e 100644
@@ -35,3 +35,4 @@ generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
 generic-y += tables.h
+generic-y += kprobes.h
include/asm-generic/kprobes.h new file +25 -0
new file mode 100644
index 000000000000..57af9f21d148
@@ -0,0 +1,25 @@
+#ifndef _ASM_GENERIC_KPROBES_H
+#define _ASM_GENERIC_KPROBES_H
+
+#if defined(__KERNEL__) && !defined(__ASSEMBLY__)
+#ifdef CONFIG_KPROBES
+/*
+ * Blacklist ganerating macro. Specify functions which is not probed
+ * by using this macro.
+ */
+# define __NOKPROBE_SYMBOL(fname)				\
+static unsigned long __used					\
+	__attribute__((__section__("_kprobe_blacklist")))	\
+	_kbl_addr_##fname = (unsigned long)fname;
+# define NOKPROBE_SYMBOL(fname)	__NOKPROBE_SYMBOL(fname)
+/* Use this to forbid a kprobes attach on very low level functions */
+# define __kprobes	__attribute__((__section__(".kprobes.text")))
+# define nokprobe_inline	__always_inline
+#else
+# define NOKPROBE_SYMBOL(fname)
+# define __kprobes
+# define nokprobe_inline	inline
+#endif
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLY__) */
+
+#endif /* _ASM_GENERIC_KPROBES_H */
include/linux/compiler.h +0 -8
index cf0fa5d86059..dca49b4099da 100644
@@ -566,12 +566,4 @@ static __always_inline void __write_once_size(volatile void *p, void *res, int s
 	(_________p1); \
 })
 
-/* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
-#ifdef CONFIG_KPROBES
-# define __kprobes	__attribute__((__section__(".kprobes.text")))
-# define nokprobe_inline	__always_inline
-#else
-# define __kprobes
-# define nokprobe_inline	inline
-#endif
 #endif /* __LINUX_COMPILER_H */
include/linux/kprobes.h +3 -16
index 8f6849084248..985ed79ef431 100644
@@ -29,7 +29,7 @@
  *		<[email protected]>  and Prasanna S Panchamukhi
  *		<[email protected]> added function-return probes.
  */
-#include <linux/compiler.h>	/* for __kprobes */
+#include <linux/compiler.h>
 #include <linux/linkage.h>
 #include <linux/list.h>
 #include <linux/notifier.h>
@@ -40,9 +40,9 @@
 #include <linux/rcupdate.h>
 #include <linux/mutex.h>
 #include <linux/ftrace.h>
+#include <asm/kprobes.h>
 
 #ifdef CONFIG_KPROBES
-#include <asm/kprobes.h>
 
 /* kprobe_status settings */
 #define KPROBE_HIT_ACTIVE	0x00000001
@@ -51,6 +51,7 @@
 #define KPROBE_HIT_SSDONE	0x00000008
 
 #else /* CONFIG_KPROBES */
+#include <asm-generic/kprobes.h>
 typedef int kprobe_opcode_t;
 struct arch_specific_insn {
 	int dummy;
@@ -481,18 +482,4 @@ static inline int enable_jprobe(struct jprobe *jp)
 	return enable_kprobe(&jp->kp);
 }
 
-#ifdef CONFIG_KPROBES
-/*
- * Blacklist ganerating macro. Specify functions which is not probed
- * by using this macro.
- */
-#define __NOKPROBE_SYMBOL(fname)			\
-static unsigned long __used				\
-	__attribute__((section("_kprobe_blacklist")))	\
-	_kbl_addr_##fname = (unsigned long)fname;
-#define NOKPROBE_SYMBOL(fname)	__NOKPROBE_SYMBOL(fname)
-#else
-#define NOKPROBE_SYMBOL(fname)
-#endif
-
 #endif /* _LINUX_KPROBES_H */
Signature · 1 line
2.11.0
author maintainer
#155 lore raw

PATCH v7 12/14 kprobes: port .kprobes.text to section range

In reply to 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 glob filters [PASS]
[12] ftrace - function profiler with function tracing [PASS]
[13] Test creation and deletion of trace instances while setting an event [PASS]
[14] Test creation and deletion of trace instances [PASS]
[15] Kprobe dynamic event - adding and removing [PASS]
[16] Kprobe dynamic event - busy event check [PASS]
[17] Kprobe dynamic event with arguments [PASS]
[18] Kprobes event arguments with types [PASS]
[19] Kprobe dynamic event with function tracer [PASS]
[20] Kretprobe dynamic event with arguments [PASS]
[21] event trigger - test event enable/disable trigger [PASS]
[22] event trigger - test trigger filter [PASS]
[23] event trigger - test histogram modifiers [PASS]
[24] event trigger - test histogram trigger [PASS]
[25] event trigger - test multiple histogram triggers [PASS]
[26] event trigger - test snapshot-trigger [PASS]
[27] event trigger - test stacktrace-trigger [PASS]
[28] event trigger - test traceon/off trigger [PASS]

v5:

o Use ..rng.* instead of .rng.* as suggested by Nicholas Piggin. This is the typical way to avoid clash with compiler generated section.

o Replace section macros with section names

v4:

o arm64 build fixes with allmodconfig

o build fix suggested for avr32 with allnoconfig, otherwise we end up with:

arch/avr32/kernel/built-in.o: In function `save_full_context_ex':
(.ex.text+0x1c4): relocation truncated to fit: R_AVR32_16N_PCREL against symbol `debug_trampoline' defined in .text.rng.kprobes.any section in arch/avr32/kernel/built-in.o
arch/avr32/kernel/built-in.o: In function `debug_exit_work':
(.text.rng.kprobes.any+0xa8): relocation truncated to fit:
R_AVR32_16N_PCREL against `.ex.text'+3aa
make: *** [Makefile:953: vmlinux] Error 1

o open-code section use on scripts/ code -- folks to prefer the simplicity over dealing with having more tool code access kernel headers.

o NOPE: include #include <asm-generic/ranges.h> on compiler.h -- solves a few 0-day compilation issues

v3:

o after v2 arch/arm/kernel/vmlinux-xip.lds.S got kprobe support, this just removes the custom linker script reference to kprobes as that is no longer needed with linker tables.

o split kprobe linker table and kprobe section ranges use into two separate patches. This should make it easier to review and also demos both distinct use types, one a linker table another a simple section range.

v2: introduced this patch in this series

---
 arch/arc/kernel/vmlinux.lds.S        |  1 -
 arch/arm/kernel/entry-armv.S         |  3 ++-
 arch/arm/kernel/vmlinux-xip.lds.S    |  1 -
 arch/arm/kernel/vmlinux.lds.S        |  1 -
 arch/arm64/kernel/armv8_deprecated.c |  1 +
 arch/arm64/kernel/probes/kprobes.c   |  4 ++--
 arch/arm64/kernel/vmlinux.lds.S      |  1 -
 arch/avr32/kernel/entry-avr32b.S     | 13 +++++++++++--
 arch/avr32/kernel/vmlinux.lds.S      |  1 -
 arch/blackfin/kernel/vmlinux.lds.S   |  1 -
 arch/c6x/kernel/vmlinux.lds.S        |  1 -
 arch/hexagon/kernel/vmlinux.lds.S    |  1 -
 arch/ia64/kernel/jprobes.S           |  3 ++-
 arch/ia64/kernel/vmlinux.lds.S       |  1 -
 arch/ia64/lib/flush.S                |  6 +++---
 arch/metag/kernel/vmlinux.lds.S      |  1 -
 arch/microblaze/kernel/vmlinux.lds.S |  1 -
 arch/mips/kernel/vmlinux.lds.S       |  1 -
 arch/mn10300/kernel/vmlinux.lds.S    |  1 -
 arch/nios2/kernel/vmlinux.lds.S      |  1 -
 arch/openrisc/kernel/vmlinux.lds.S   |  1 -
 arch/parisc/kernel/vmlinux.lds.S     |  1 -
 arch/powerpc/include/asm/ppc_asm.h   |  1 +
 arch/powerpc/kernel/vmlinux.lds.S    |  1 -
 arch/s390/kernel/entry.S             |  5 +++--
 arch/s390/kernel/kprobes.c           |  6 +++---
 arch/s390/kernel/mcount.S            |  3 ++-
 arch/s390/kernel/vmlinux.lds.S       |  1 -
 arch/score/kernel/vmlinux.lds.S      |  1 -
 arch/sh/kernel/vmlinux.lds.S         |  1 -
 arch/sparc/kernel/vmlinux.lds.S      |  1 -
 arch/sparc/mm/ultra.S                |  3 ++-
 arch/tile/kernel/vmlinux.lds.S       |  1 -
 arch/x86/kernel/kprobes/core.c       | 11 +++++------
 arch/x86/kernel/vmlinux.lds.S        |  1 -
 include/asm-generic/kprobes.h        |  3 ++-
 include/asm-generic/sections.h       |  2 --
 include/asm-generic/vmlinux.lds.h    |  2 +-
 include/linux/kprobes.h              |  3 +++
 kernel/kprobes.c                     |  6 ++++--
 scripts/mod/modpost.c                |  2 +-
 scripts/recordmcount.c               |  2 +-
 scripts/recordmcount.pl              |  2 +-
 43 files changed, 50 insertions(+), 54 deletions(-)
arch/arc/kernel/vmlinux.lds.S +0 -1
index f35ed578e007..dd05c86eb96e 100644
@@ -91,7 +91,6 @@ SECTIONS
 		SCHED_TEXT
 		CPUIDLE_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		*(.fixup)
 		*(.gnu.warning)
 	}
arch/arm/kernel/entry-armv.S +2 -1
index 9f157e7c51e7..c455b491b6d3 100644
@@ -34,6 +34,7 @@
 #include "entry-header.S"
 #include <asm/entry-macro-multi.S>
 #include <asm/probes.h>
+#include <asm/ranges.h>
 
 /*
  * Interrupt handling.
@@ -83,7 +84,7 @@
 	.endm
 
 #ifdef CONFIG_KPROBES
-	.section	.kprobes.text,"ax",%progbits
+	set_section_rng_type(.text, kprobes, ax, %progbits)
 #else
 	.text
 #endif
arch/arm/kernel/vmlinux-xip.lds.S +0 -1
index 37b2a11af345..1a84f84b8165 100644
@@ -103,7 +103,6 @@ SECTIONS
 			SCHED_TEXT
 			CPUIDLE_TEXT
 			LOCK_TEXT
-			KPROBES_TEXT
 			*(.gnu.warning)
 			*(.glue_7)
 			*(.glue_7t)
arch/arm/kernel/vmlinux.lds.S +0 -1
index f7f55df0bf7b..1e278e6c3506 100644
@@ -114,7 +114,6 @@ SECTIONS
 			CPUIDLE_TEXT
 			LOCK_TEXT
 			HYPERVISOR_TEXT
-			KPROBES_TEXT
 			*(.gnu.warning)
 			*(.glue_7)
 			*(.glue_7t)
arch/arm64/kernel/armv8_deprecated.c +1 -0
index 86032a012388..4043a14c9e36 100644
@@ -21,6 +21,7 @@
 #include <asm/traps.h>
 #include <linux/uaccess.h>
 #include <asm/cpufeature.h>
+#include <asm/kprobes.h>
 
 #define CREATE_TRACE_POINTS
 #include "trace-events-emulation.h"
arch/arm64/kernel/probes/kprobes.c +2 -2
index f0593c92279b..ec288dd165cb 100644
@@ -23,6 +23,7 @@
 #include <linux/slab.h>
 #include <linux/stop_machine.h>
 #include <linux/stringify.h>
+#include <linux/ranges.h>
 #include <asm/traps.h>
 #include <asm/ptrace.h>
 #include <asm/cacheflush.h>
@@ -540,8 +541,7 @@ int __kprobes longjmp_break_handler(struct kprobe *p, struct pt_regs *regs)
 
 bool arch_within_kprobe_blacklist(unsigned long addr)
 {
-	if ((addr >= (unsigned long)__kprobes_text_start &&
-	    addr < (unsigned long)__kprobes_text_end) ||
+	if (SECTION_RANGE_ADDR_WITHIN(kprobes, addr) ||
 	    (addr >= (unsigned long)__entry_text_start &&
 	    addr < (unsigned long)__entry_text_end) ||
 	    (addr >= (unsigned long)__idmap_text_start &&
arch/arm64/kernel/vmlinux.lds.S +0 -1
index b8deffa9e1bf..c68e5d528706 100644
@@ -124,7 +124,6 @@ SECTIONS
 			SCHED_TEXT
 			CPUIDLE_TEXT
 			LOCK_TEXT
-			KPROBES_TEXT
 			HYPERVISOR_TEXT
 			IDMAP_TEXT
 			HIBERNATE_TEXT
arch/avr32/kernel/entry-avr32b.S +11 -2
index 7301f4806bbe..7b2a5c5ef047 100644
@@ -23,6 +23,7 @@
 #include <asm/sysreg.h>
 #include <asm/thread_info.h>
 #include <asm/unistd.h>
+#include <asm/ranges.h>
 
 #ifdef CONFIG_PREEMPT
 # define preempt_stop		mask_interrupts
@@ -605,7 +606,11 @@ fault_exit_work:
 	brcc	fault_resume_user
 	rjmp	enter_monitor_mode
 
-	.section .kprobes.text, "ax", @progbits
+#ifdef CONFIG_KPROBES
+	set_section_rng_type(.text, kprobes, ax, @progbits)
+#else
+	.text
+#endif
 	.type	handle_debug, @function
 handle_debug:
 	sub	sp, 4		/* r12_orig */
@@ -826,7 +831,11 @@ irq_level\level:
 	IRQ_LEVEL 2
 	IRQ_LEVEL 3
 
-	.section .kprobes.text, "ax", @progbits
+#ifdef CONFIG_KPROBES
+	set_section_rng_type(.text, kprobes, ax, @progbits)
+#else
+	.text
+#endif
 	.type	enter_monitor_mode, @function
 enter_monitor_mode:
 	/*
arch/avr32/kernel/vmlinux.lds.S +0 -1
index 17f2730eb497..04627a9c178e 100644
@@ -49,7 +49,6 @@ SECTIONS
 		_stext = .;
 		*(.ex.text)
 		*(.irq.text)
-		KPROBES_TEXT
 		TEXT_TEXT
 		SCHED_TEXT
 		CPUIDLE_TEXT
arch/blackfin/kernel/vmlinux.lds.S +0 -1
index 68069a120055..93220ff65014 100644
@@ -37,7 +37,6 @@ SECTIONS
 		LOCK_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
-		KPROBES_TEXT
 #ifdef CONFIG_ROMKERNEL
 		__sinittext = .;
 		INIT_TEXT
arch/c6x/kernel/vmlinux.lds.S +0 -1
index a1a5c166bc9b..a41d43b8254b 100644
@@ -74,7 +74,6 @@ SECTIONS
 		LOCK_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
-		KPROBES_TEXT
 		*(.fixup)
 		*(.gnu.warning)
 	}
arch/hexagon/kernel/vmlinux.lds.S +0 -1
index ec87e67feb19..7e6f68584b55 100644
@@ -52,7 +52,6 @@ SECTIONS
 		SCHED_TEXT
 		CPUIDLE_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		*(.fixup)
 	}
 	_etext = .;
arch/ia64/kernel/jprobes.S +2 -1
index f69389c7be1d..71adc7132e22 100644
@@ -46,11 +46,12 @@
  */
 #include <asm/asmmacro.h>
 #include <asm/break.h>
+#include <asm/ranges.h>
 
 	/*
 	 * void jprobe_break(void)
 	 */
-	.section .kprobes.text, "ax"
+	set_section_rng(.text, kprobes, ax)
 ENTRY(jprobe_break)
 	break.m __IA64_BREAK_JPROBE
 END(jprobe_break)
arch/ia64/kernel/vmlinux.lds.S +0 -1
index f89d20c97412..3ff6edf913d2 100644
@@ -48,7 +48,6 @@ SECTIONS {
 		SCHED_TEXT
 		CPUIDLE_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		*(.gnu.linkonce.t*)
 	}
 
arch/ia64/lib/flush.S +3 -3
index 9a5a2f9fad13..dec1b180d618 100644
@@ -9,7 +9,7 @@
 
 #include <asm/asmmacro.h>
 #include <asm/export.h>
-
+#include <asm/ranges.h>
 
 	/*
 	 * flush_icache_range(start,end)
@@ -21,7 +21,7 @@
 	 *
 	 *	Note: "in0" and "in1" are preserved for debugging purposes.
 	 */
-	.section .kprobes.text,"ax"
+	set_section_rng(.text, kprobes, ax)
 GLOBAL_ENTRY(flush_icache_range)
 
 	.prologue
@@ -74,7 +74,7 @@ EXPORT_SYMBOL_GPL(flush_icache_range)
 	 *
 	 *	Note: "in0" and "in1" are preserved for debugging purposes.
 	 */
-	.section .kprobes.text,"ax"
+	set_section_rng(.text, kprobes, ax)
 GLOBAL_ENTRY(clflush_cache_range)
 
 	.prologue
arch/metag/kernel/vmlinux.lds.S +0 -1
index e6c700eaf207..b18386d2250f 100644
@@ -23,7 +23,6 @@ SECTIONS
 	SCHED_TEXT
 	CPUIDLE_TEXT
 	LOCK_TEXT
-	KPROBES_TEXT
 	IRQENTRY_TEXT
 	SOFTIRQENTRY_TEXT
 	*(.text.*)
arch/microblaze/kernel/vmlinux.lds.S +0 -1
index 289d0e7f3e3a..aadee2229ac6 100644
@@ -35,7 +35,6 @@ SECTIONS {
 		SCHED_TEXT
 		CPUIDLE_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		. = ALIGN (4) ;
arch/mips/kernel/vmlinux.lds.S +0 -1
index f0a0e6d62be3..44e21812c544 100644
@@ -57,7 +57,6 @@ SECTIONS
 		SCHED_TEXT
 		CPUIDLE_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		*(.text.*)
arch/mn10300/kernel/vmlinux.lds.S +0 -1
index 2d5f1c3f1afb..552ef00a3da5 100644
@@ -32,7 +32,6 @@ SECTIONS
 	SCHED_TEXT
 	CPUIDLE_TEXT
 	LOCK_TEXT
-	KPROBES_TEXT
 	*(.fixup)
 	*(.gnu.warning)
 	} = 0xcb
arch/nios2/kernel/vmlinux.lds.S +0 -1
index 6a8045bb1a77..aae4a00c4056 100644
@@ -41,7 +41,6 @@ SECTIONS
 		LOCK_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
-		KPROBES_TEXT
 	} =0
 	_etext = .;
 
arch/openrisc/kernel/vmlinux.lds.S +0 -1
index 00ddb7804be4..8ade6ccca6ac 100644
@@ -57,7 +57,6 @@ SECTIONS
 	  SCHED_TEXT
 	  CPUIDLE_TEXT
 	  LOCK_TEXT
-	  KPROBES_TEXT
 	  IRQENTRY_TEXT
 	  SOFTIRQENTRY_TEXT
 	  *(.fixup)
arch/parisc/kernel/vmlinux.lds.S +0 -1
index 3d6ef1b29c6a..edbd6d9487dc 100644
@@ -71,7 +71,6 @@ SECTIONS
 		SCHED_TEXT
 		CPUIDLE_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		*(.text.do_softirq)
arch/powerpc/include/asm/ppc_asm.h +1 -0
index 025833b8df9f..0846413b3a2e 100644
@@ -9,6 +9,7 @@
 #include <asm/processor.h>
 #include <asm/ppc-opcode.h>
 #include <asm/firmware.h>
+#include <asm/ranges.h>
 
 #ifdef __ASSEMBLY__
 
arch/powerpc/kernel/vmlinux.lds.S +0 -1
index 8cd940c72895..2285664abb52 100644
@@ -112,7 +112,6 @@ SECTIONS
 		SCHED_TEXT
 		CPUIDLE_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		MEM_KEEP(init.text)
arch/s390/kernel/entry.S +3 -2
index 97298c58b2be..847e2e1df89c 100644
@@ -24,6 +24,7 @@
 #include <asm/setup.h>
 #include <asm/nmi.h>
 #include <asm/export.h>
+#include <asm/ranges.h>
 
 __PT_R0      =	__PT_GPRS
 __PT_R1      =	__PT_GPRS + 8
@@ -169,7 +170,7 @@ _PIF_WORK	= (_PIF_PER_TRAP)
 		tm	off+\addr, \mask
 	.endm
 
-	.section .kprobes.text, "ax"
+	set_section_rng(.text, kprobes, ax)
 .Ldummy:
 	/*
 	 * This nop exists only in order to avoid that __switch_to starts at
@@ -986,7 +987,7 @@ ENTRY(restart_int_handler)
 	brc	2,2b
 3:	j	3b
 
-	.section .kprobes.text, "ax"
+	set_section_rng(.text, kprobes, ax)
 
 #ifdef CONFIG_CHECK_STACK
 /*
arch/s390/kernel/kprobes.c +3 -3
index 84e0557b16fe..94a4918b5968 100644
@@ -289,9 +289,9 @@ static void kprobe_reenter_check(struct kprobe_ctlblk *kcb, struct kprobe *p)
 	case KPROBE_REENTER:
 	default:
 		/*
-		 * A kprobe on the code path to single step an instruction
-		 * is a BUG. The code path resides in the .kprobes.text
-		 * section and is executed with interrupts disabled.
+		 * A kprobe on the code path to single step an instruction is a
+		 * BUG. The code path resides in the kprobes section range and
+		 * is executed with interrupts disabled.
 		 */
 		printk(KERN_EMERG "Invalid kprobe detected at %p.\n", p->addr);
 		dump_kprobe(p);
arch/s390/kernel/mcount.S +2 -1
index 9a17e4475d27..9d76056609f7 100644
@@ -10,8 +10,9 @@
 #include <asm/ftrace.h>
 #include <asm/ptrace.h>
 #include <asm/export.h>
+#include <asm/ranges.h>
 
-	.section .kprobes.text, "ax"
+	set_section_rng(.text, kprobes, ax)
 
 ENTRY(ftrace_stub)
 	br	%r14
arch/s390/kernel/vmlinux.lds.S +0 -1
index 3667d20e997f..b2df6d9bab09 100644
@@ -37,7 +37,6 @@ SECTIONS
 		SCHED_TEXT
 		CPUIDLE_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		*(.fixup)
arch/score/kernel/vmlinux.lds.S +0 -1
index 4117890b1db1..a8b14f3ed474 100644
@@ -42,7 +42,6 @@ SECTIONS
 		SCHED_TEXT
 		CPUIDLE_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		*(.text.*)
 		*(.fixup)
 		. = ALIGN (4) ;
arch/sh/kernel/vmlinux.lds.S +0 -1
index 5b9a3cc90c58..58d9ba796f7a 100644
@@ -38,7 +38,6 @@ SECTIONS
 		SCHED_TEXT
 		CPUIDLE_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		*(.fixup)
arch/sparc/kernel/vmlinux.lds.S +0 -1
index 572db686f845..0ee41b0071e5 100644
@@ -51,7 +51,6 @@ SECTIONS
 		SCHED_TEXT
 		CPUIDLE_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
 		*(.gnu.warning)
arch/sparc/mm/ultra.S +2 -1
index 5d2fd6cd3189..ee9f648549c0 100644
@@ -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
@@ -185,7 +186,7 @@ __spitfire_flush_tlb_mm_slow:
 /*
  * The following code flushes one page_size worth.
  */
-	.section .kprobes.text, "ax"
+	set_section_rng(.text, kprobes, ax)
 	.align		32
 	.globl		__flush_icache_page
 __flush_icache_page:	/* %o0 = phys_page */
arch/tile/kernel/vmlinux.lds.S +0 -1
index e1baf094fba4..85d03ce6c0a0 100644
@@ -44,7 +44,6 @@ SECTIONS
     SCHED_TEXT
     CPUIDLE_TEXT
     LOCK_TEXT
-    KPROBES_TEXT
     IRQENTRY_TEXT
     SOFTIRQENTRY_TEXT
     __fix_text_end = .;   /* tile-cpack won't rearrange before this */
arch/x86/kernel/kprobes/core.c +5 -6
index eb3509338ae0..95e4b172e923 100644
@@ -580,9 +580,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);
@@ -1133,10 +1133,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_RANGE_ADDR_WITHIN(kprobes, addr) ||
 		(addr >= (unsigned long)__entry_text_start &&
-		 addr < (unsigned long)__entry_text_end);
+		 addr < (unsigned long)__entry_text_end));
 }
 
 int __init arch_init_kprobes(void)
arch/x86/kernel/vmlinux.lds.S +0 -1
index e79f15f108a8..4c16fadb9ac6 100644
@@ -99,7 +99,6 @@ SECTIONS
 		SCHED_TEXT
 		CPUIDLE_TEXT
 		LOCK_TEXT
-		KPROBES_TEXT
 		ENTRY_TEXT
 		IRQENTRY_TEXT
 		SOFTIRQENTRY_TEXT
include/asm-generic/kprobes.h +2 -1
index 57af9f21d148..02a26b975187 100644
@@ -3,6 +3,7 @@
 
 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
 #ifdef CONFIG_KPROBES
+#include <asm/ranges.h>
 /*
  * Blacklist ganerating macro. Specify functions which is not probed
  * by using this macro.
@@ -13,7 +14,7 @@ static unsigned long __used					\
 	_kbl_addr_##fname = (unsigned long)fname;
 # define NOKPROBE_SYMBOL(fname)	__NOKPROBE_SYMBOL(fname)
 /* Use this to forbid a kprobes attach on very low level functions */
-# define __kprobes	__attribute__((__section__(".kprobes.text")))
+# define __kprobes	__LINUX_RANGE(.text, kprobes)
 # define nokprobe_inline	__always_inline
 #else
 # define NOKPROBE_SYMBOL(fname)
include/asm-generic/sections.h +0 -2
index b145ae8d9cbe..f3340f2772bb 100644
@@ -26,7 +26,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
  */
@@ -38,7 +37,6 @@ extern char _sinittext[], _einittext[];
 extern char __start_data_ro_after_init[], __end_data_ro_after_init[];
 extern char _end[];
 extern char __per_cpu_load[], __per_cpu_start[], __per_cpu_end[];
-extern char __kprobes_text_start[], __kprobes_text_end[];
 extern char __entry_text_start[], __entry_text_end[];
 extern char __start_rodata[], __end_rodata[];
 
include/asm-generic/vmlinux.lds.h +1 -1
index 37b99537d5a9..499caf5b4361 100644
@@ -471,7 +471,7 @@
 #define KPROBES_TEXT							\
 		ALIGN_FUNCTION();					\
 		VMLINUX_SYMBOL(__kprobes_text_start) = .;		\
-		*(.kprobes.text)					\
+		*(.text..rng.kprobes.any)				\
 		VMLINUX_SYMBOL(__kprobes_text_end) = .;
 
 #define ENTRY_TEXT							\
include/linux/kprobes.h +3 -0
index 985ed79ef431..445cc6fe7afa 100644
@@ -43,6 +43,9 @@
 #include <asm/kprobes.h>
 
 #ifdef CONFIG_KPROBES
+#include <linux/ranges.h>
+
+DECLARE_SECTION_RANGE(kprobes);
 
 /* kprobe_status settings */
 #define KPROBE_HIT_ACTIVE	0x00000001
kernel/kprobes.c +4 -2
index 43460104f119..82191f328e21 100644
@@ -1328,8 +1328,7 @@ static int register_aggr_kprobe(struct kprobe *orig_p, struct kprobe *p)
 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_RANGE_ADDR_WITHIN(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, .text);
+
 static int __init init_kprobes(void)
 {
 	int i, err = 0;
scripts/mod/modpost.c +1 -1
index 29c89a6bad3d..2b442234c69b 100644
@@ -894,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", ".cpuidle.text"
+		".text..rng.kprobes.any", ".cpuidle.text"
 #define OTHER_TEXT_SECTIONS ".ref.text", ".head.text", ".spinlock.text", \
 		".fixup", ".entry.text", ".exception.text", ".text.*", \
 		".coldtext"
scripts/recordmcount.c +1 -1
index aeb34223167c..6e95f3f87db1 100644
@@ -417,7 +417,7 @@ is_mcounted_section_name(char const *const txtname)
 		strcmp(".spinlock.text", txtname) == 0 ||
 		strcmp(".irqentry.text", txtname) == 0 ||
 		strcmp(".softirqentry.text", txtname) == 0 ||
-		strcmp(".kprobes.text", txtname) == 0 ||
+		strcmp(".text..rng.kprobes.any", txtname) == 0 ||
 		strcmp(".cpuidle.text", txtname) == 0 ||
 		strcmp(".text.unlikely", txtname) == 0;
 }
scripts/recordmcount.pl +1 -1
index 0b6002b36f20..15e2fa37c489 100755
@@ -135,7 +135,7 @@ my %text_sections = (
      ".spinlock.text" => 1,
      ".irqentry.text" => 1,
      ".softirqentry.text" => 1,
-     ".kprobes.text" => 1,
+     ".text..rng.kprobes.any" => 1,
      ".cpuidle.text" => 1,
      ".text.unlikely" => 1,
 );
Signature · 1 line
2.11.0
author maintainer
#156 lore raw

PATCH v7 13/14 kprobes: port blacklist kprobes to linker table

In reply to 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

v5: Use push_section_tbl() for _ASM_NOKPROBE() for x86, and
_ASM_NOKPROBE_SYMBOL() on powerpc
v4: ported over _ASM_NOKPROBE_SYMBOL() on powerpc and
ASM_NOKPROBE() on x86
v3: this patch was introduced in this series

---
 arch/powerpc/include/asm/ppc_asm.h |  4 ++--
 arch/x86/include/asm/asm.h         |  4 +++-
 include/asm-generic/kprobes.h      |  4 ++--
 include/asm-generic/vmlinux.lds.h  | 10 ----------
 include/linux/kprobes.h            |  2 ++
 kernel/kprobes.c                   | 11 ++++-------
 6 files changed, 13 insertions(+), 22 deletions(-)
arch/powerpc/include/asm/ppc_asm.h +2 -2
index 0846413b3a2e..20cd9c00eef5 100644
@@ -9,7 +9,7 @@
 #include <asm/processor.h>
 #include <asm/ppc-opcode.h>
 #include <asm/firmware.h>
-#include <asm/ranges.h>
+#include <asm/tables.h>
 
 #ifdef __ASSEMBLY__
 
@@ -266,7 +266,7 @@ GLUE(.,name):
  */
 #ifdef CONFIG_KPROBES
 #define _ASM_NOKPROBE_SYMBOL(entry)			\
-	.pushsection "_kprobe_blacklist","aw";		\
+	push_section_tbl(.init.data, _kprobe_blacklist, any, aw); \
 	PPC_LONG (entry) ;				\
 	.popsection
 #else
arch/x86/include/asm/asm.h +3 -1
index 7acb51c49fec..48b1bc85c0e6 100644
@@ -1,6 +1,8 @@
 #ifndef _ASM_X86_ASM_H
 #define _ASM_X86_ASM_H
 
+#include <asm/tables.h>
+
 #ifdef __ASSEMBLY__
 # define __ASM_FORM(x)	x
 # define __ASM_FORM_RAW(x)     x
@@ -74,7 +76,7 @@
 	_ASM_EXTABLE_HANDLE(from, to, ex_handler_ext)
 
 # define _ASM_NOKPROBE(entry)					\
-	.pushsection "_kprobe_blacklist","aw" ;			\
+	push_section_tbl_any(.init.data, _kprobe_blacklist, aw);\
 	_ASM_ALIGN ;						\
 	_ASM_PTR (entry);					\
 	.popsection
include/asm-generic/kprobes.h +2 -2
index 02a26b975187..7d29a208390e 100644
@@ -3,14 +3,14 @@
 
 #if defined(__KERNEL__) && !defined(__ASSEMBLY__)
 #ifdef CONFIG_KPROBES
+#include <linux/tables.h>
 #include <asm/ranges.h>
 /*
  * Blacklist ganerating macro. Specify functions which is not probed
  * by using this macro.
  */
 # define __NOKPROBE_SYMBOL(fname)				\
-static unsigned long __used					\
-	__attribute__((__section__("_kprobe_blacklist")))	\
+static LINKTABLE_INIT_DATA(_kprobe_blacklist, all)		\
 	_kbl_addr_##fname = (unsigned long)fname;
 # define NOKPROBE_SYMBOL(fname)	__NOKPROBE_SYMBOL(fname)
 /* Use this to forbid a kprobes attach on very low level functions */
include/asm-generic/vmlinux.lds.h +0 -10
index 499caf5b4361..9f062af1f728 100644
@@ -114,15 +114,6 @@
 #define BRANCH_PROFILE()
 #endif
 
-#ifdef CONFIG_KPROBES
-#define KPROBE_BLACKLIST()	. = ALIGN(8);				      \
-				VMLINUX_SYMBOL(__start_kprobe_blacklist) = .; \
-				KEEP(*(_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) = .;	\
@@ -551,7 +542,6 @@
 	*(.init.rodata)							\
 	FTRACE_EVENTS()							\
 	TRACE_SYSCALLS()						\
-	KPROBE_BLACKLIST()						\
 	MEM_DISCARD(init.rodata)					\
 	CLK_OF_TABLES()							\
 	RESERVEDMEM_OF_TABLES()						\
include/linux/kprobes.h +2 -0
index 445cc6fe7afa..2707820cbb56 100644
@@ -44,8 +44,10 @@
 
 #ifdef CONFIG_KPROBES
 #include <linux/ranges.h>
+#include <linux/tables.h>
 
 DECLARE_SECTION_RANGE(kprobes);
+DECLARE_LINKTABLE(unsigned long, _kprobe_blacklist);
 
 /* kprobe_status settings */
 #define KPROBE_HIT_ACTIVE	0x00000001
kernel/kprobes.c +4 -7
index 82191f328e21..9d102ac95256 100644
@@ -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, .text);
@@ -2143,8 +2141,7 @@ static int __init init_kprobes(void)
 		raw_spin_lock_init(&(kretprobe_table_locks[i].lock));
 	}
 
-	err = populate_kprobe_blacklist(__start_kprobe_blacklist,
-					__stop_kprobe_blacklist);
+	err = populate_kprobe_blacklist();
 	if (err) {
 		pr_err("kprobes: failed to populate blacklist: %d\n", err);
 		pr_err("Please take care of using kprobes.\n");
Signature · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author maintainer
#157 lore raw

PATCH v7 14/14 lib: add linker tables test driver

In reply to Luis R. Rodriguez

Add a test drivers for linker tables.

v7: address ./scripts/checkpatch.pl --codespell issues
v6: rename table macro as suggested by Andy Shevchenko
v5: added this commit for the first time in this series.

---
 lib/Kconfig.debug                        |   6 +
 lib/Makefile                             |   1 +
 lib/test_linktables/Makefile             |  13 +
 lib/test_linktables/test-linktables-00.c |  27 ++
 lib/test_linktables/test-linktables-01.c |  27 ++
 lib/test_linktables/test-linktables-02.c |  27 ++
 lib/test_linktables/test-linktables-03.c |  27 ++
 lib/test_linktables/test-linktables-04.c |  27 ++
 lib/test_linktables/test-linktables.c    | 801 +++++++++++++++++++++++++++++++
 lib/test_linktables/test-linktables.h    |  48 ++
 10 files changed, 1004 insertions(+)
 create mode 100644 lib/test_linktables/Makefile
 create mode 100644 lib/test_linktables/test-linktables-00.c
 create mode 100644 lib/test_linktables/test-linktables-01.c
 create mode 100644 lib/test_linktables/test-linktables-02.c
 create mode 100644 lib/test_linktables/test-linktables-03.c
 create mode 100644 lib/test_linktables/test-linktables-04.c
 create mode 100644 lib/test_linktables/test-linktables.c
 create mode 100644 lib/test_linktables/test-linktables.h
lib/Kconfig.debug +6 -0
index 643bce5a5b02..dbbcbb16951d 100644
@@ -1839,6 +1839,12 @@ config TEST_HASH
 	  This is intended to help people writing architecture-specific
 	  optimized versions.  If unsure, say N.
 
+config TEST_LINKTABLES
+	bool "Test linker table functionality"
+	default n
+	help
+	  Enable this option to test the kernel's linker table functionality.
+
 endmenu # runtime tests
 
 config PROVIDE_OHCI1394_DMA_INIT
lib/Makefile +1 -0
index f5e72a728285..899b2f363ef1 100644
@@ -56,6 +56,7 @@ obj-$(CONFIG_TEST_STATIC_KEYS) += test_static_key_base.o
 obj-$(CONFIG_TEST_PRINTF) += test_printf.o
 obj-$(CONFIG_TEST_BITMAP) += test_bitmap.o
 obj-$(CONFIG_TEST_UUID) += test_uuid.o
+obj-$(CONFIG_TEST_LINKTABLES) += test_linktables/
 
 ifeq ($(CONFIG_DEBUG_KOBJECT),y)
 CFLAGS_kobject.o += -DDEBUG
lib/test_linktables/Makefile new file +13 -0
new file mode 100644
index 000000000000..a1a67d7fd57a
@@ -0,0 +1,13 @@
+__LINKTABLE_TESTS := $(shell find ./ -name test-linktables-\*.c | wc -l)
+ccflags-y += -D__LINKTABLE_TESTS=$(__LINKTABLE_TESTS)
+
+# Keep these disorganized, if linker tables did not work then
+# things would not be ordered for us automatically at link time.
+# Linker tables grants us the ability to be explicit about
+# order.
+obj-$(CONFIG_TEST_LINKTABLES) += test-linktables-04.o
+obj-$(CONFIG_TEST_LINKTABLES) += test-linktables-02.o
+obj-$(CONFIG_TEST_LINKTABLES) += test-linktables-01.o
+obj-$(CONFIG_TEST_LINKTABLES) += test-linktables-03.o
+obj-$(CONFIG_TEST_LINKTABLES) += test-linktables-00.o
+obj-$(CONFIG_TEST_LINKTABLES) += test-linktables.o
lib/test_linktables/test-linktables-00.c new file +27 -0
new file mode 100644
index 000000000000..ea162bd69179
@@ -0,0 +1,27 @@
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/tables.h>
+#include <linux/printk.h>
+
+#include "test-linktables.h"
+
+static int __init test_linktable_00_init(int input)
+{
+	return 0 * input;
+}
+
+static int __initdata test_linktable_00_init_data(int input)
+{
+	return 0 * input;
+}
+
+static int test_linktable_00(int input)
+{
+	return 0 * input;
+}
+
+test_linktable_init_data(00, test_linktable_00_init_data); /* .init.data */
+test_linktable_init_text(00, test_linktable_00_init); /* .init.text */
+test_linktable(00, test_linktable_00); /* .data */
+test_linktable_text(00, test_linktable_00); /* .text */
+test_linktable_rodata(00, test_linktable_00); /* .rodata */
lib/test_linktables/test-linktables-01.c new file +27 -0
new file mode 100644
index 000000000000..39578990fd59
@@ -0,0 +1,27 @@
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/tables.h>
+#include <linux/printk.h>
+
+#include "test-linktables.h"
+
+static int __init test_linktable_01_init(int input)
+{
+	return 1 * input;
+}
+
+static int __initdata test_linktable_01_init_data(int input)
+{
+	return 1 * input;
+}
+
+static int test_linktable_01(int input)
+{
+	return 1 * input;
+}
+
+test_linktable_init_data(01, test_linktable_01_init_data); /* .init.data */
+test_linktable_init_text(01, test_linktable_01_init); /* .init.text */
+test_linktable(01, test_linktable_01); /* .data */
+test_linktable_text(01, test_linktable_01); /* .text */
+test_linktable_rodata(01, test_linktable_01); /* .rodata */
lib/test_linktables/test-linktables-02.c new file +27 -0
new file mode 100644
index 000000000000..7f4b34240ecb
@@ -0,0 +1,27 @@
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/tables.h>
+#include <linux/printk.h>
+
+#include "test-linktables.h"
+
+static int __init test_linktable_02_init(int input)
+{
+	return 2 * input;
+}
+
+static int __initdata test_linktable_02_init_data(int input)
+{
+	return 2 * input;
+}
+
+static int test_linktable_02(int input)
+{
+	return 2 * input;
+}
+
+test_linktable_init_data(02, test_linktable_02_init_data); /* .init.data */
+test_linktable_init_text(02, test_linktable_02_init); /* .init.text */
+test_linktable(02, test_linktable_02); /* .data */
+test_linktable_text(02, test_linktable_02); /* .text */
+test_linktable_rodata(02, test_linktable_02); /* .rodata */
lib/test_linktables/test-linktables-03.c new file +27 -0
new file mode 100644
index 000000000000..47ca77e30c24
@@ -0,0 +1,27 @@
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/tables.h>
+#include <linux/printk.h>
+
+#include "test-linktables.h"
+
+static int __init test_linktable_03_init(int input)
+{
+	return 3 * input;
+}
+
+static int __initdata test_linktable_03_init_data(int input)
+{
+	return 3 * input;
+}
+
+static int test_linktable_03(int input)
+{
+	return 3 * input;
+}
+
+test_linktable_init_data(03, test_linktable_03_init_data); /* .init.data */
+test_linktable_init_text(03, test_linktable_03_init); /* .init.text */
+test_linktable(03, test_linktable_03); /* .data */
+test_linktable_text(03, test_linktable_03); /* .text */
+test_linktable_rodata(03, test_linktable_03); /* .rodata */
lib/test_linktables/test-linktables-04.c new file +27 -0
new file mode 100644
index 000000000000..4123e0e16715
@@ -0,0 +1,27 @@
+#define pr_fmt(fmt) KBUILD_MODNAME ": " fmt
+
+#include <linux/tables.h>
+#include <linux/printk.h>
+
+#include "test-linktables.h"
+
+static int __init test_linktable_04_init(int input)
+{
+	return 4 * input;
+}
+
+static int __initdata test_linktable_04_init_data(int input)
+{
+	return 4 * input;
+}
+
+static int test_linktable_04(int input)
+{
+	return 4 * input;
+}
+
+test_linktable_init_data(04, test_linktable_04_init_data); /* .init.data */
+test_linktable_init_text(04, test_linktable_04_init); /* .init.text */
+test_linktable(04, test_linktable_04); /* .data */
+test_linktable_text(04, test_linktable_04); /* .text */
+test_linktable_rodata(04, test_linktable_04); /* .rodata */
lib/test_linktables/test-linktables.c new file +801 -0

801 lines not on this page · raw message

lib/test_linktables/test-linktables.h new file +48 -0

48 lines not on this page · raw message

Signature · 1 line
2.11.0