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 2 of 3

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

PATCH v4 6/6 tools: add userspace linker table sandbox

In reply to Luis R. Rodriguez

Add a userspace sandbox to allow easy experimentation and test extensions with linker tables, section ranges and the new section core definitions.

The userspace sandbox tries to mimic the Linux kernel development flow as much as possible, it however relies on and uses libc. Support is currently only provided to x86_64.

Demo run:

cd tools/linker-tables
make clean; make;
./demo
Initializing x86 bare metal world
x86-init: Number of init entries: 8
Initializing memory ...
Completed initializing memory !
Initializing pci ...
PCI fixup size: 1
Demo: Using LINKTABLE_FOR_EACH
foo_fixup
Demo: Using LINKTABLE_RUN_ALL
foo_fixup
Completed initializing pci !
Number of init entries: 1
Initializing kprobes ...
== OK: test_kprobe_0001 within range!
== OK: test_kprobe_0002 not in range as expected! Completed initializing kprobes !
Initializing kasan ...
Early init for Kasan...
Completed initializing kasan !
Initializing beta ...
Completed initializing beta !
Initializing alpha ...
Completed initializing alpha !
Booting bare metal
Calling start_kernel()...
ACME: Initializing ...
ACME: Finished init ... !
Synthetics: synth_init_or(2) returns: 0xDEADBEEF
Synthetics: ps_shr(0xDEADBEEF, get_demo_shr) returns: 0x0000DEAD

v7: address ./scripts/checkpatch.pl --codespell complaints

v6: rename table macros as suggested by Andy Shevchenko

v5:

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

o moves tools/include/linux/printk.h to tools linker-table/include/linux/printk.h -- we cannot generalize this just yet, more work is needed in terms of providing a namespace for headers for types of ports of kernel functionality to userspace.

o Adjust code according to the latest discussions for the linker tables API (section name macros are now gone).

o Give CONFIG_HAVE_ARCH_PS_CONST for x86 another good 'ol college try, still fails, but this is just a demo anyway. We can amend and fix make this more optimized for x86 later. Thanks Boris!

v4: this patch is new in this series -- added to the kenrel as
suggested by Boris, as otherwise it'd be really hard to keep an external userspace repository in sync.

Cc Adrian Hunter <[email protected]>
Cc David Ahern <[email protected]>
Cc Jiri Olsa <[email protected]>
Cc Namhyung Kim <[email protected]>
Cc Wang Nan <[email protected]>
Cc Arnaldo Carvalho de Melo <[email protected]>
---
 Documentation/sections/linker-tables.rst           |   4 +-
 MAINTAINERS                                        |   1 +
 include/linux/tables.h                             |   5 +-
 tools/Makefile                                     |   3 +-
 .../arch/x86/include/generated/asm/section-core.h  |   1 +
 tools/arch/x86/include/generated/ranges.h          |   1 +
 tools/arch/x86/include/generated/tables.h          |   1 +
 tools/include/asm-generic/ranges.h                 |  93 +++
 tools/include/asm-generic/section-core.h           | 348 +++++++++++
 tools/include/asm-generic/tables.h                 |  48 ++
 tools/include/linux/ranges.h                       | 183 ++++++
 tools/include/linux/sections.h                     |  87 +++
 tools/include/linux/string.h                       |   1 +
 tools/include/linux/tables.h                       | 684 +++++++++++++++++++++
 tools/linker-tables/.gitignore                     |   2 +
 tools/linker-tables/Makefile                       | 184 ++++++
 tools/linker-tables/README                         | 114 ++++
 tools/linker-tables/arch/x86/include/asm/asm.h     |  17 +
 tools/linker-tables/arch/x86/include/asm/boot.h    |   1 +
 .../linker-tables/arch/x86/include/asm/bootparam.h |  32 +
 tools/linker-tables/arch/x86/include/asm/kprobes.h |   7 +
 .../linker-tables/arch/x86/include/asm/ps_const.h  |  23 +
 tools/linker-tables/arch/x86/include/asm/ranges.h  |   6 +
 .../arch/x86/include/asm/section-core.h            |   1 +
 tools/linker-tables/arch/x86/include/asm/setup.h   |   6 +
 tools/linker-tables/arch/x86/include/asm/tables.h  |   6 +
 tools/linker-tables/arch/x86/include/asm/x86.h     |   4 +
 .../arch/x86/include/asm/x86_init_fn.h             | 169 +++++
 tools/linker-tables/arch/x86/kernel/alpha.c        |  10 +
 tools/linker-tables/arch/x86/kernel/alternative.c  |  31 +
 tools/linker-tables/arch/x86/kernel/beta.c         |  10 +
 tools/linker-tables/arch/x86/kernel/head64.c       |  58 ++
 tools/linker-tables/arch/x86/kernel/init.c         |  42 ++
 tools/linker-tables/arch/x86/kernel/kasan.c        |  11 +
 tools/linker-tables/arch/x86/kernel/kprobes.c      |  51 ++
 tools/linker-tables/arch/x86/kernel/vmlinux.lds.S  | 277 +++++++++
 tools/linker-tables/arch/x86/mm/init.c             |  11 +
 tools/linker-tables/arch/x86/xen/init.c            |  13 +
 tools/linker-tables/drivers/acme.c                 |  33 +
 tools/linker-tables/drivers/synth/common.c         |  16 +
 tools/linker-tables/drivers/synth/common.h         |   2 +
 tools/linker-tables/drivers/synth/main.c           |  36 ++
 tools/linker-tables/drivers/synth/or.S             |  39 ++
 tools/linker-tables/drivers/synth/synth.h          |   2 +
 tools/linker-tables/drivers/xen-driver.c           |  12 +
 .../include/asm-generic/arch_init_fn.h             |  50 ++
 tools/linker-tables/include/asm-generic/kprobes.h  |  26 +
 tools/linker-tables/include/linux/bitops.h         |   6 +
 tools/linker-tables/include/linux/init.h           |  40 ++
 tools/linker-tables/include/linux/kasan.h          |   5 +
 tools/linker-tables/include/linux/kernel.h         |   2 +
 tools/linker-tables/include/linux/kprobes.h        |  11 +
 tools/linker-tables/include/linux/module.h         |  14 +
 tools/linker-tables/include/linux/mutex.h          |  17 +
 tools/linker-tables/include/linux/pci.h            |   7 +
 tools/linker-tables/include/linux/printk.h         |  26 +
 tools/linker-tables/include/linux/ps_const.h       |  46 ++
 tools/linker-tables/include/linux/sched.h          |   9 +
 tools/linker-tables/include/linux/spinlock.h       |  13 +
 tools/linker-tables/include/linux/start_kernel.h   |   1 +
 tools/linker-tables/include/linux/types.h          |  13 +
 tools/linker-tables/include/linux/workqueue.h      |  51 ++
 tools/linker-tables/include/xen/xen.h              |   4 +
 tools/linker-tables/kernel/locking/mutex.c         |  28 +
 tools/linker-tables/kernel/locking/spinlock.c      |  26 +
 tools/linker-tables/kernel/main.c                  |  32 +
 tools/linker-tables/kernel/workqueue.c             |  43 ++
 tools/linker-tables/lib/string.c                   |  26 +
 tools/linker-tables/main.c                         |  20 +
 tools/linker-tables/pci-quirks.c                   |  14 +
 tools/linker-tables/pci.c                          |  30 +
 71 files changed, 3241 insertions(+), 5 deletions(-)
 create mode 100644 tools/arch/x86/include/generated/asm/section-core.h
 create mode 100644 tools/arch/x86/include/generated/ranges.h
 create mode 100644 tools/arch/x86/include/generated/tables.h
 create mode 100644 tools/include/asm-generic/ranges.h
 create mode 100644 tools/include/asm-generic/section-core.h
 create mode 100644 tools/include/asm-generic/tables.h
 create mode 100644 tools/include/linux/ranges.h
 create mode 100644 tools/include/linux/sections.h
 create mode 100644 tools/include/linux/tables.h
 create mode 100644 tools/linker-tables/.gitignore
 create mode 100644 tools/linker-tables/Makefile
 create mode 100644 tools/linker-tables/README
 create mode 100644 tools/linker-tables/arch/x86/include/asm/asm.h
 create mode 100644 tools/linker-tables/arch/x86/include/asm/boot.h
 create mode 100644 tools/linker-tables/arch/x86/include/asm/bootparam.h
 create mode 100644 tools/linker-tables/arch/x86/include/asm/kprobes.h
 create mode 100644 tools/linker-tables/arch/x86/include/asm/ps_const.h
 create mode 100644 tools/linker-tables/arch/x86/include/asm/ranges.h
 create mode 100644 tools/linker-tables/arch/x86/include/asm/section-core.h
 create mode 100644 tools/linker-tables/arch/x86/include/asm/setup.h
 create mode 100644 tools/linker-tables/arch/x86/include/asm/tables.h
 create mode 100644 tools/linker-tables/arch/x86/include/asm/x86.h
 create mode 100644 tools/linker-tables/arch/x86/include/asm/x86_init_fn.h
 create mode 100644 tools/linker-tables/arch/x86/kernel/alpha.c
 create mode 100644 tools/linker-tables/arch/x86/kernel/alternative.c
 create mode 100644 tools/linker-tables/arch/x86/kernel/beta.c
 create mode 100644 tools/linker-tables/arch/x86/kernel/head64.c
 create mode 100644 tools/linker-tables/arch/x86/kernel/init.c
 create mode 100644 tools/linker-tables/arch/x86/kernel/kasan.c
 create mode 100644 tools/linker-tables/arch/x86/kernel/kprobes.c
 create mode 100644 tools/linker-tables/arch/x86/kernel/vmlinux.lds.S
 create mode 100644 tools/linker-tables/arch/x86/mm/init.c
 create mode 100644 tools/linker-tables/arch/x86/xen/init.c
 create mode 100644 tools/linker-tables/drivers/acme.c
 create mode 100644 tools/linker-tables/drivers/synth/common.c
 create mode 100644 tools/linker-tables/drivers/synth/common.h
 create mode 100644 tools/linker-tables/drivers/synth/main.c
 create mode 100644 tools/linker-tables/drivers/synth/or.S
 create mode 100644 tools/linker-tables/drivers/synth/synth.h
 create mode 100644 tools/linker-tables/drivers/xen-driver.c
 create mode 100644 tools/linker-tables/include/asm-generic/arch_init_fn.h
 create mode 100644 tools/linker-tables/include/asm-generic/kprobes.h
 create mode 100644 tools/linker-tables/include/linux/bitops.h
 create mode 100644 tools/linker-tables/include/linux/init.h
 create mode 100644 tools/linker-tables/include/linux/kasan.h
 create mode 100644 tools/linker-tables/include/linux/kernel.h
 create mode 100644 tools/linker-tables/include/linux/kprobes.h
 create mode 100644 tools/linker-tables/include/linux/module.h
 create mode 100644 tools/linker-tables/include/linux/mutex.h
 create mode 100644 tools/linker-tables/include/linux/pci.h
 create mode 100644 tools/linker-tables/include/linux/printk.h
 create mode 100644 tools/linker-tables/include/linux/ps_const.h
 create mode 100644 tools/linker-tables/include/linux/sched.h
 create mode 100644 tools/linker-tables/include/linux/spinlock.h
 create mode 100644 tools/linker-tables/include/linux/start_kernel.h
 create mode 100644 tools/linker-tables/include/linux/types.h
 create mode 100644 tools/linker-tables/include/linux/workqueue.h
 create mode 100644 tools/linker-tables/include/xen/xen.h
 create mode 100644 tools/linker-tables/kernel/locking/mutex.c
 create mode 100644 tools/linker-tables/kernel/locking/spinlock.c
 create mode 100644 tools/linker-tables/kernel/main.c
 create mode 100644 tools/linker-tables/kernel/workqueue.c
 create mode 100644 tools/linker-tables/lib/string.c
 create mode 100644 tools/linker-tables/main.c
 create mode 100644 tools/linker-tables/pci-quirks.c
 create mode 100644 tools/linker-tables/pci.c
Documentation/sections/linker-tables.rst +2 -2
index bc2d9f46cde6..2f2bb1fc0798 100644
@@ -11,11 +11,11 @@ About Linker tables
 .. kernel-doc:: include/linux/tables.h
    :doc: Introduction
 
-Linker table provenance
+Linker table provenance and userspace testing
 ---------------------------------------------
 
 .. kernel-doc:: include/linux/tables.h
-   :doc: Linker table provenance
+   :doc: Linker table provenance and userspace testing
 
 Benefits of using Linker tables
 ===============================
MAINTAINERS +1 -0
index cee1efd50e04..b83bd957011e 100644
@@ -5429,6 +5429,7 @@ L:	[email protected]
 S:	Supported
 F:	include/asm-generic/tables.h
 F:	include/linux/tables.h
+F:	tools/linker-tables/
 F:	Documentation/sections/linker-tables.rst
 
 GENERIC PHY FRAMEWORK
include/linux/tables.h +3 -2
index f295fbe74734..9dd8f947b60b 100644
@@ -35,12 +35,13 @@
  */
 
 /**
- * DOC: Linker table provenance
+ * DOC: Linker table provenance and userspace testing
  *
  * The Linux implementation of linker tables was inspired by the iPXE linker
  * table's solution (iPXE commit 67a10ef000cb7 "[contrib] Add rom-o-matic to
  * contrib "[0]).  To see how this code evolved refer to the out of tree
- * userspace linker-table tree [1].
+ * userspace linker-table tree [1]. Linux has a similar userspace application
+ * in tools/linker-tables/ to help more easily test adding new extensions.
  *
  * Contrary to iPXE's solution which strives to force compilation of
  * everything using linker tables, Linux's solution allows for developers to be
tools/Makefile +2 -1
index 00caacd3ed92..ecb2e651c930 100644
@@ -19,6 +19,7 @@ help:
 	@echo '  kvm_stat               - top-like utility for displaying kvm statistics'
 	@echo '  leds                   - LEDs  tools'
 	@echo '  lguest                 - a minimal 32-bit x86 hypervisor'
+	@echo '  linker-tables		- userspace liker table sandbox and related tools'
 	@echo '  net                    - misc networking tools'
 	@echo '  perf                   - Linux performance measurement and analysis tool'
 	@echo '  selftests              - various kernel selftests'
@@ -86,7 +87,7 @@ tmon: FORCE
 freefall: FORCE
 	$(call descend,laptop/$@)
 
-all: acpi cgroup cpupower gpio hv firewire lguest \
+all: acpi cgroup cpupower gpio hv firewire lguest linker-tables \
 		perf selftests turbostat usb \
 		virtio vm net x86_energy_perf_policy \
 		tmon freefall objtool
tools/arch/x86/include/generated/asm/section-core.h new file +1 -0
new file mode 100644
index 000000000000..06be2b1c424f
@@ -0,0 +1 @@
+#include <asm-generic/section-core.h>
tools/arch/x86/include/generated/ranges.h new file +1 -0
new file mode 100644
index 000000000000..dac1a9a11367
@@ -0,0 +1 @@
+#include <asm-generic/ranges.h>
tools/arch/x86/include/generated/tables.h new file +1 -0
new file mode 100644
index 000000000000..d437818275c5
@@ -0,0 +1 @@
+#include <asm-generic/tables.h>
tools/include/asm-generic/ranges.h new file +93 -0

93 lines not on this page · raw message

tools/include/asm-generic/section-core.h new file +348 -0

348 lines not on this page · raw message

tools/include/asm-generic/tables.h new file +48 -0

48 lines not on this page · raw message

tools/include/linux/ranges.h new file +183 -0

183 lines not on this page · raw message

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

87 lines not on this page · raw message

tools/include/linux/string.h +1 -0
index f436d2420a18..a6b12564bbd9 100644
@@ -3,6 +3,7 @@
 
 
 #include <linux/types.h>	/* for size_t */
+#include <string.h>
 
 void *memdup(const void *src, size_t len);
 
tools/include/linux/tables.h new file +684 -0

684 lines not on this page · raw message

tools/linker-tables/.gitignore new file +2 -0
new file mode 100644
index 000000000000..8275b0c55385
@@ -0,0 +1,2 @@
+arch/x86/kernel/vmlinux.lds
+demo
tools/linker-tables/Makefile new file +184 -0

184 lines not on this page · raw message

tools/linker-tables/README new file +114 -0

114 lines not on this page · raw message

tools/linker-tables/arch/x86/include/asm/asm.h new file +17 -0
new file mode 100644
index 000000000000..155a52920dfb
@@ -0,0 +1,17 @@
+#ifndef _ASM_X86_ASM_H
+
+#ifdef __ASSEMBLY__
+# define __ASM_FORM(x)	x
+# define __ASM_FORM_RAW(x)     x
+# define __ASM_FORM_COMMA(x) x,
+#else
+# define __ASM_FORM(x)	" " #x " "
+# define __ASM_FORM_RAW(x)     #x
+# define __ASM_FORM_COMMA(x) " " #x ","
+#endif
+
+# define __ASM_SEL(a,b) __ASM_FORM(b)
+# define __ASM_SEL_RAW(a,b) __ASM_FORM_RAW(b)
+#define _ASM_PTR	__ASM_SEL(.long, .quad)
+
+#endif /* _ASM_X86_ASM_H */
tools/linker-tables/arch/x86/include/asm/boot.h new file +1 -0
new file mode 100644
index 000000000000..af91b94ad5a6
@@ -0,0 +1 @@
+extern struct boot_params boot_params;
tools/linker-tables/arch/x86/include/asm/bootparam.h new file +32 -0
new file mode 100644
index 000000000000..a7ef34216f7f
@@ -0,0 +1,32 @@
+#ifndef __BOOTPARAM_H
+#define __BOOTPARAM_H
+
+#include <linux/types.h>
+
+struct setup_header {
+	__u32 hardware_subarch;
+} __attribute__((packed));
+
+struct boot_params {
+	struct setup_header hdr;
+} __attribute__((packed));
+
+enum {
+	X86_SUBARCH_PC = 0,
+	X86_SUBARCH_LGUEST,
+	X86_SUBARCH_XEN,
+	X86_SUBARCH_INTEL_MID,
+	X86_SUBARCH_CE4100,
+	X86_NR_SUBARCHS,
+};
+
+#define X86_SUBARCH_ALL_SUBARCHS 	\
+	(				\
+	BIT(X86_SUBARCH_PC) |		\
+	BIT(X86_SUBARCH_LGUEST) |	\
+	BIT(X86_SUBARCH_XEN) |		\
+	BIT(X86_SUBARCH_INTEL_MID) |	\
+	BIT(X86_SUBARCH_CE4100)		\
+	)
+
+#endif /* __BOOTPARAM_H */
tools/linker-tables/arch/x86/include/asm/kprobes.h new file +7 -0
new file mode 100644
index 000000000000..f702fc359efe
@@ -0,0 +1,7 @@
+#ifndef _SANDBOX_ASM_X86_KPROBES_H
+#define _SANDBOX_ASM_X86_KPROBES_H
+
+/* This is all we need for the demo */
+#include <asm-generic/kprobes.h>
+
+#endif /* _SANDBOX_ASM_X86_KPROBES_H */
tools/linker-tables/arch/x86/include/asm/ps_const.h new file +23 -0
new file mode 100644
index 000000000000..3847f03fca92
@@ -0,0 +1,23 @@
+#ifndef __X86_PS_CONST
+#define __X86_PS_CONST
+
+#include <linux/stringify.h>
+#include <linux/tables.h>
+#include <asm/asm.h>
+
+#define ps_shr(in, _func)						\
+({									\
+	 __typeof__(in) _count;						\
+									\
+	asm volatile(							\
+		"shr %P[_in],%[_count]\n"				\
+		"1:\n"							\
+		push_section_tbl(.init.data, ps_set_const_table, 01,)	\
+		_ASM_PTR "1b-1, %P2, %P3\n"				\
+		".popsection\n"						\
+		: [_count] "=g" (_count)				\
+		: [_in] "i" (in), "i" (SET_CONST_U8), "i" (_func));	\
+	(_count);							\
+})
+
+#endif /* __X86_PS_CONST */
tools/linker-tables/arch/x86/include/asm/ranges.h new file +6 -0
new file mode 100644
index 000000000000..823789d2b010
@@ -0,0 +1,6 @@
+#ifndef _ASM_X86_RANGES_H
+#define _ASM_X86_RANGES_H
+
+#include <asm-generic/ranges.h>
+
+#endif  /* _ASM_X86_RANGES_H */
tools/linker-tables/arch/x86/include/asm/section-core.h new file +1 -0
new file mode 100644
index 000000000000..06be2b1c424f
@@ -0,0 +1 @@
+#include <asm-generic/section-core.h>
tools/linker-tables/arch/x86/include/asm/setup.h new file +6 -0
new file mode 100644
index 000000000000..366c36bd2910
@@ -0,0 +1,6 @@
+#ifndef __LINUX_X86_USER_SETUP_H
+#define __LINUX_X86_USER_SETUP_H
+
+/* I'm lazy */
+
+#endif /* __LINUX_X86_USER_SETUP_H */
tools/linker-tables/arch/x86/include/asm/tables.h new file +6 -0
new file mode 100644
index 000000000000..797df3407ee1
@@ -0,0 +1,6 @@
+#ifndef _ASM_X86_TABLES_H
+#define _ASM_X86_TABLES_H
+
+#include <asm-generic/tables.h>
+
+#endif  /* _ASM_X86_RANGES_H */
tools/linker-tables/arch/x86/include/asm/x86.h new file +4 -0
new file mode 100644
index 000000000000..680c1141e0de
@@ -0,0 +1,4 @@
+int startup_64(void);
+int x86_64_start_reservations(void);
+void setup_arch(void);
+void late_init(void);
tools/linker-tables/arch/x86/include/asm/x86_init_fn.h new file +169 -0

169 lines not on this page · raw message

tools/linker-tables/arch/x86/kernel/alpha.c new file +10 -0
new file mode 100644
index 000000000000..477227d817a3
@@ -0,0 +1,10 @@
+#include <linux/kernel.h>
+#include <asm/x86_init_fn.h>
+
+static void early_init_alpha(void)
+{
+	pr_info("Initializing alpha ...\n");
+	pr_info("Completed initializing alpha !\n");
+}
+
+x86_init_early_pc(early_init_alpha);
tools/linker-tables/arch/x86/kernel/alternative.c new file +31 -0
new file mode 100644
index 000000000000..380c184172b3
@@ -0,0 +1,31 @@
+#include <asm/x86_init_fn.h>
+
+#include <linux/kernel.h>
+#include <linux/ps_const.h>
+
+void apply_alternatives_linker_tables(void)
+{
+	unsigned int num_consts = LINKTABLE_SIZE(ps_set_const_table);
+	struct ps_set_const *ps_const;
+
+	if (!num_consts)
+		return;
+
+	pr_debug("Number of init entries: %d\n", num_consts);
+
+	linktable_for_each(ps_const, ps_set_const_table) {
+		switch (ps_const->type) {
+		case SET_CONST_U8:
+			*ps_const->count = (__u8) ps_const->func();
+			break;
+		case SET_CONST_U16:
+			*ps_const->count = (__u16) ps_const->func();
+			break;
+		case SET_CONST_U32:
+			*ps_const->count = (__u16) ps_const->func();
+			break;
+		}
+	}
+}
+
+x86_init_early_pc(apply_alternatives_linker_tables);
tools/linker-tables/arch/x86/kernel/beta.c new file +10 -0
new file mode 100644
index 000000000000..6cbbb3144928
@@ -0,0 +1,10 @@
+#include <linux/kernel.h>
+#include <asm/x86_init_fn.h>
+
+static void early_init_beta(void)
+{
+	pr_info("Initializing beta ...\n");
+	pr_info("Completed initializing beta !\n");
+}
+
+x86_init_early_pc(early_init_beta);
tools/linker-tables/arch/x86/kernel/head64.c new file +58 -0

58 lines not on this page · raw message

tools/linker-tables/arch/x86/kernel/init.c new file +42 -0

42 lines not on this page · raw message

tools/linker-tables/arch/x86/kernel/kasan.c new file +11 -0
new file mode 100644
index 000000000000..a1e6a5b72c23
@@ -0,0 +1,11 @@
+#include <linux/kernel.h>
+#include <asm/x86_init_fn.h>
+
+void kasan_early_init(void)
+{
+	pr_info("Initializing kasan ...\n");
+	pr_info("Early init for Kasan...\n");
+	pr_info("Completed initializing kasan !\n");
+}
+
+x86_init_early_pc(kasan_early_init);
tools/linker-tables/arch/x86/kernel/kprobes.c new file +51 -0

51 lines not on this page · raw message

tools/linker-tables/arch/x86/kernel/vmlinux.lds.S new file +277 -0

277 lines not on this page · raw message

tools/linker-tables/arch/x86/mm/init.c new file +11 -0
new file mode 100644
index 000000000000..33e5700e2864
@@ -0,0 +1,11 @@
+#include <linux/kernel.h>
+#include <asm/x86_init_fn.h>
+
+static void early_init_memory(void)
+{
+	pr_info("Initializing memory ...\n");
+	sleep(1);
+	pr_info("Completed initializing memory !\n");
+}
+
+x86_init_early_all(early_init_memory);
tools/linker-tables/arch/x86/xen/init.c new file +13 -0
new file mode 100644
index 000000000000..40ad493daee8
@@ -0,0 +1,13 @@
+#include <linux/kernel.h>
+#include <linux/tables.h>
+#include <asm/x86_init_fn.h>
+#include <asm/x86.h>
+
+void startup_xen(void)
+{
+	pr_info("Initializing Xen guest\n");
+
+	x86_init_fn_early_init();
+
+	x86_64_start_reservations();
+}
tools/linker-tables/drivers/acme.c new file +33 -0
new file mode 100644
index 000000000000..975e4b8bf48d
@@ -0,0 +1,33 @@
+#define pr_fmt(fmt) "ACME: " fmt
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/workqueue.h>
+
+void *acme_todo(void *arg);
+static DECLARE_WORK(acme_work, acme_todo);
+
+void *acme_todo(void *arg)
+{
+	pr_info("Running scheduled work\n");
+	pthread_exit(NULL);
+}
+
+static int acme_init_driver(void)
+{
+	pr_info("Initializing ...\n");
+	sleep(2);
+	pr_info("Finished init ... !\n");
+
+	init_work(&acme_work);
+	schedule_work(&acme_work);
+
+	return 0;
+}
+module_init(acme_init_driver);
+
+static void acme_exit(void)
+{
+	cancel_work_sync(&acme_work);
+};
+module_exit(acme_exit);
tools/linker-tables/drivers/synth/common.c new file +16 -0
new file mode 100644
index 000000000000..b44d9fcc7a9b
@@ -0,0 +1,16 @@
+int demo_or_1(int arg)
+{
+	switch (arg) {
+	case 1:
+		return 0xDEA00000;
+	case 2:
+		return 0X000D0000;
+	default:
+		return arg * 2;
+	}
+}
+
+int demo_or_2(void)
+{
+	return 0x0000BEEF;
+}
tools/linker-tables/drivers/synth/common.h new file +2 -0
new file mode 100644
index 000000000000..92827004f532
@@ -0,0 +1,2 @@
+int demo_or_1(int arg);
+int demo_or_2(void);
tools/linker-tables/drivers/synth/main.c new file +36 -0
new file mode 100644
index 000000000000..b9c2f876afa0
@@ -0,0 +1,36 @@
+#define pr_fmt(fmt) "Synthetics: " fmt
+
+#include <linux/module.h>
+#include <linux/kernel.h>
+#include <linux/ps_const.h>
+
+#include "common.h"
+#include "synth.h"
+
+DEFINE_LINKTABLE_INIT_DATA(struct ps_set_const, ps_set_const_table);
+
+unsigned int get_demo_shr(void)
+{
+	return 16;
+}
+
+static int synth_init(void)
+{
+	int synth_or;
+	int val = 2;
+	const unsigned int reg =  ps_shr(0xDEADBEEF, get_demo_shr);
+
+	synth_or = synth_init_or(val);
+	pr_info("synth_init_or(%d) returns: 0x%08X\n", val, synth_or);
+
+	pr_info("ps_shr(0x%08X, get_demo_shr) returns: 0x%08X\n",
+		0xDEADBEEF, reg);
+
+	return 0;
+}
+module_init(synth_init);
+
+static void synth_exit(void)
+{
+}
+module_exit(synth_exit);
tools/linker-tables/drivers/synth/or.S new file +39 -0
new file mode 100644
index 000000000000..deb963fdae33
@@ -0,0 +1,39 @@
+#include <asm/ranges.h>
+
+	DEFINE_SECTION_RANGE(.text, synth_init_or)
+
+	push_section_rng_level(.text, synth_init_or, "01", )
+	/* err = 0; */
+	pushq %rbp
+	movq %rsp,%rbp
+	pushq %rbx
+	xorq %rbx,%rbx
+	.popsection
+
+	push_section_rng_level(.text, synth_init_or, "99", )
+	/* return err; */
+	movq %rbx,%rax
+	popq %rbx
+	popq %rbp
+	retq
+	.popsection
+
+	push_section_rng_level(.text, synth_init_or, "50", )
+	/* err |= demo_or_1(1); */
+	movl $1,%edi
+	call demo_or_1
+	orq %rax,%rbx
+	.popsection
+
+	push_section_rng_level(.text, synth_init_or, "50", )
+	/* err |= demo_or_1(2); */
+	movl $2,%edi
+	call demo_or_1
+	orq %rax,%rbx
+	.popsection
+
+	push_section_rng_level(.text, synth_init_or, "50", )
+	/* err |= demo_or_2(); */
+	call demo_or_2
+	orq %rax,%rbx
+	.popsection
tools/linker-tables/drivers/synth/synth.h new file +2 -0
new file mode 100644
index 000000000000..abbb9afac374
@@ -0,0 +1,2 @@
+/* Synthetic demos go here */
+int synth_init_or(int arg);
tools/linker-tables/drivers/xen-driver.c new file +12 -0
new file mode 100644
index 000000000000..268166efd06c
@@ -0,0 +1,12 @@
+#include <asm/x86_init_fn.h>
+#include <linux/kernel.h>
+#include <linux/pci.h>
+#include <xen/xen.h>
+
+static void early_xen_init_driver(void)
+{
+	pr_info("Initializing xen driver\n");
+	sleep(2);
+}
+
+x86_init_early_xen(early_xen_init_driver);
tools/linker-tables/include/asm-generic/arch_init_fn.h new file +50 -0

50 lines not on this page · raw message

tools/linker-tables/include/asm-generic/kprobes.h new file +26 -0
new file mode 100644
index 000000000000..839d2eb464d3
@@ -0,0 +1,26 @@
+#ifndef _SANDBOX_ASM_GENERIC_KPROBES_H
+#define _SANDBOX_ASM_GENERIC_KPROBES_H
+
+#if defined(__KERNEL__) && !defined(__ASSEMBLY__)
+#ifdef CONFIG_KPROBES
+#include <linux/tables.h>
+#include <asm/ranges.h>
+/*
+ * Blacklist ganerating macro. Specify functions which is not probed
+ * by using this macro.
+ */
+# define __NOKPROBE_SYMBOL(fname)				\
+static LINKTABLE_INIT_DATA(_kprobe_blacklist, all)		\
+	_kbl_addr_##fname = (unsigned long)fname;
+# define NOKPROBE_SYMBOL(fname)	__NOKPROBE_SYMBOL(fname)
+/* Use this to forbid a kprobes attach on very low level functions */
+# define __kprobes	__LINUX_RANGE(.text, kprobes)
+# define nokprobe_inline	__always_inline
+#else
+# define NOKPROBE_SYMBOL(fname)
+# define __kprobes
+# define nokprobe_inline	inline
+#endif
+#endif /* defined(__KERNEL__) && !defined(__ASSEMBLY__) */
+
+#endif /* _SANDBOX_ASM_GENERIC_KPROBES_H */
tools/linker-tables/include/linux/bitops.h new file +6 -0
new file mode 100644
index 000000000000..2960e8089ebc
@@ -0,0 +1,6 @@
+#ifndef _LINUX_BITOPS_H
+#define _LINUX_BITOPS_H
+
+#define BIT(nr)		(1UL << (nr))
+
+#endif /* _LINUX_BITOPS_H */
tools/linker-tables/include/linux/init.h new file +40 -0
new file mode 100644
index 000000000000..2691c3697f48
@@ -0,0 +1,40 @@
+#ifndef _SANDBOX_LINUX_INIT_H
+#define _SANDBOX_LINUX_INIT_H
+
+#include_next <linux/init.h>
+#include <linux/types.h>
+#include <linux/sections.h>
+
+#define __init	__section(.init.text)
+#define __exit	__section(.exit.text)
+
+#ifndef __ASSEMBLY__
+#include <linux/tables.h>
+typedef int (*initcall_t)(void);
+typedef void (*exitcall_t)(void);
+
+DECLARE_LINKTABLE(initcall_t, init_calls);
+DECLARE_LINKTABLE(exitcall_t, exit_calls);
+
+#define __define_initcall(fn, id)					\
+	static LINKTABLE_INIT_DATA(init_calls, id)			\
+	__initcall_##fn##id = fn
+
+#define pure_initcall(fn)			__define_initcall(fn, 0)
+#define core_initcall(fn)			__define_initcall(fn, 1)
+#define postcore_initcall(fn)			__define_initcall(fn, 2)
+#define arch_initcall(fn)			__define_initcall(fn, 3)
+#define subsys_initcall(fn)			__define_initcall(fn, 4)
+#define fs_initcall(fn)				__define_initcall(fn, 5)
+#define device_initcall(fn)			__define_initcall(fn, 6)
+#define late_initcall(fn)			__define_initcall(fn, 7)
+
+#define __initcall(fn)				device_initcall(fn)
+
+#define __exitcall(fn)							\
+	static LINKTABLE_INIT_DATA(exit_calls, any)			\
+	__exitcall_##fn = fn;
+
+#endif
+
+#endif /* _SANDBOX_LINUX_INIT_H */
tools/linker-tables/include/linux/kasan.h new file +5 -0
new file mode 100644
index 000000000000..41791187854e
@@ -0,0 +1,5 @@
+#include <linux/types.h>
+
+void kasan_early_init(void);
+int kasan_init(void);
+bool is_kasan_setup(void);
tools/linker-tables/include/linux/kernel.h new file +2 -0
new file mode 100644
index 000000000000..e2857c0b5b11
@@ -0,0 +1,2 @@
+#include_next <linux/kernel.h>
+#include <linux/printk.h>
tools/linker-tables/include/linux/kprobes.h new file +11 -0
new file mode 100644
index 000000000000..ecd5a0a69ae6
@@ -0,0 +1,11 @@
+#ifndef _SANDBOX_LINUX_KPROBES_H
+#define _SANDBOX_LINUX_KPROBES_H
+
+#include <asm/kprobes.h>
+#include <linux/ranges.h>
+
+#ifdef CONFIG_KPROBES
+DECLARE_SECTION_RANGE(kprobes);
+#endif
+
+#endif /* _SANDBOX_LINUX_KPROBES_H */
tools/linker-tables/include/linux/module.h new file +14 -0
new file mode 100644
index 000000000000..b59e55f3f04e
@@ -0,0 +1,14 @@
+#ifndef _LINUX_MODULE_H
+#define _LINUX_MODULE_H
+
+#include <linux/init.h>
+
+#define module_init(x)  __initcall(x);
+#define module_exit(x)  __exitcall(x);
+
+struct module {
+	int (*init)(void);
+	void (*exit)(void);
+};
+
+#endif /* _LINUX_MODULE_H */
tools/linker-tables/include/linux/mutex.h new file +17 -0
new file mode 100644
index 000000000000..a74f951ceb42
@@ -0,0 +1,17 @@
+#ifndef __LINUX_MUTEX_H
+#define __LINUX_MUTEX_H
+
+#include <sys/types.h>
+#include <linux/sched.h>
+#include <pthread.h>
+
+struct mutex {
+	pthread_mutex_t lock;
+};
+
+void mutex_init(struct mutex *lock);
+void mutex_destroy(struct mutex *lock);
+void mutex_lock(struct mutex *lock);
+void mutex_unlock(struct mutex *lock);
+
+#endif /* __LINUX_MUTEX_H */
tools/linker-tables/include/linux/pci.h new file +7 -0
new file mode 100644
index 000000000000..8518c46631f7
@@ -0,0 +1,7 @@
+#include <linux/types.h>
+
+struct pci_fixup {
+	void (*hook)(void);
+};
+
+bool detect_pci(void);
tools/linker-tables/include/linux/printk.h new file +26 -0
new file mode 100644
index 000000000000..dc137d3421e8
@@ -0,0 +1,26 @@
+#ifndef _SANDBOX_KERNEL_PRINTK
+#define _SANDBOX_KERNEL_PRINTK
+
+#ifdef __KERNEL__
+
+#include <stdio.h>
+
+#ifndef pr_fmt
+#define pr_fmt(fmt)	fmt
+#endif
+
+#ifndef pr_info
+#define pr_info(fmt, ...)	printf(pr_fmt(fmt), ##__VA_ARGS__)
+#endif
+
+#ifndef pr_err
+#define pr_err(fmt, ...)	printf(pr_fmt(fmt), ##__VA_ARGS__)
+#endif
+
+#ifndef pr_debug
+#define pr_debug(fmt, ...)	printf(pr_fmt(fmt), ##__VA_ARGS__)
+#endif
+
+#endif /* __KERNEL__ */
+
+#endif /* _SANDBOX_KERNEL_PRINTK */
tools/linker-tables/include/linux/ps_const.h new file +46 -0

46 lines not on this page · raw message

tools/linker-tables/include/linux/sched.h new file +9 -0
new file mode 100644
index 000000000000..0fe3526e88bf
@@ -0,0 +1,9 @@
+#ifndef _LINUX_SCHED_H
+#define _LINUX_SCHED_H
+
+#include <linux/ranges.h>
+
+DECLARE_SECTION_RANGE(sched_text);
+#define __sched		__LINUX_RANGE(.text, sched_text)
+
+#endif /* _LINUX_SCHED_H */
tools/linker-tables/include/linux/spinlock.h new file +13 -0
new file mode 100644
index 000000000000..e62bc3bc5e6a
@@ -0,0 +1,13 @@
+#ifndef __LINUX_SPINLOCK_H
+#define __LINUX_SPINLOCK_H
+
+#include <pthread.h>
+
+#define spinlock_t pthread_spinlock_t
+
+void spin_lock_init(spinlock_t *lock);
+void spin_lock_destroy(spinlock_t *lock);
+void spin_lock(spinlock_t *lock);
+void spin_unlock(spinlock_t *lock);
+
[… more lines in the raw message]

Lines of this file are not shown. View the raw message.

tools/linker-tables/include/linux/start_kernel.h new file +1 -0
new file mode 100644
index 000000000000..5c2cb9a5cb0c

Lines of this file are not shown. View the raw message.

tools/linker-tables/include/linux/types.h new file +13 -0
new file mode 100644
index 000000000000..3fc87b2c84e2

Lines of this file are not shown. View the raw message.

tools/linker-tables/include/linux/workqueue.h new file +51 -0

51 lines not on this page · raw message

tools/linker-tables/include/xen/xen.h new file +4 -0
new file mode 100644
index 000000000000..782c799a0064

Lines of this file are not shown. View the raw message.

tools/linker-tables/kernel/locking/mutex.c new file +28 -0
new file mode 100644
index 000000000000..950e4a18461e

Lines of this file are not shown. View the raw message.

tools/linker-tables/kernel/locking/spinlock.c new file +26 -0
new file mode 100644
index 000000000000..5be2bc7cdece

Lines of this file are not shown. View the raw message.

tools/linker-tables/kernel/main.c new file +32 -0
new file mode 100644
index 000000000000..ad7a19c038bf

Lines of this file are not shown. View the raw message.

tools/linker-tables/kernel/workqueue.c new file +43 -0

43 lines not on this page · raw message

tools/linker-tables/lib/string.c new file +26 -0
new file mode 100644
index 000000000000..95631c742f1d

Lines of this file are not shown. View the raw message.

tools/linker-tables/main.c new file +20 -0
new file mode 100644
index 000000000000..c0b1f4c95112

Lines of this file are not shown. View the raw message.

tools/linker-tables/pci-quirks.c new file +14 -0
new file mode 100644
index 000000000000..8aac79477eab

Lines of this file are not shown. View the raw message.

tools/linker-tables/pci.c new file +30 -0
new file mode 100644
index 000000000000..a452c0766800

Lines of this file are not shown. View the raw message.

The rest of this diff is not shown. View the raw message.

Signature · 1 line
2.11.0

Part of the diff is not shown here. View the raw message.

maintainer
#88 lore raw

Re: [PATCH v4 6/6] tools: add userspace linker table sandbox

Quoted 7 lines · Luis R. Rodriguez

Add a userspace sandbox to allow easy experimentation and test extensions with linker tables, section ranges and the new section core definitions.

The userspace sandbox tries to mimic the Linux kernel development flow as much as possible, it however relies on and uses libc. Support is currently only provided to x86_64.

Why is x86_64 a requirement?

Quoted 27 lines

Demo run:

cd tools/linker-tables
make clean; make;
./demo
Initializing x86 bare metal world
x86-init: Number of init entries: 8
Initializing memory ...
Completed initializing memory !
Initializing pci ...
PCI fixup size: 1
Demo: Using LINKTABLE_FOR_EACH
foo_fixup
Demo: Using LINKTABLE_RUN_ALL
foo_fixup
Completed initializing pci !
Number of init entries: 1
Initializing kprobes ...
== OK: test_kprobe_0001 within range!
== OK: test_kprobe_0002 not in range as expected!
Completed initializing kprobes !
Initializing kasan ...
Early init for Kasan...
Completed initializing kasan !
Initializing beta ...
Completed initializing beta !

Quoted 8 lines

Initializing alpha ...
Completed initializing alpha !
Booting bare metal
Calling start_kernel()...
ACME: Initializing ...
ACME: Finished init ... !
Synthetics: synth_init_or(2) returns: 0xDEADBEEF
Synthetics: ps_shr(0xDEADBEEF, get_demo_shr) returns: 0x0000DEAD

Why isn't this tied into the kernel testing framework?

thanks,

greg k-h

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

author maintainer
#89 lore raw

v5 cover linux: generalize sections, ranges and linker tables

In reply to [email protected]

Posting this for *after* the merge window.

This v5 addresses feedback from the last v4 series [0] about 4 months ago. The first RFC series was posted just 1 year ago, last December 15 [1], its been a long way coming. The largest amount of feedback from the v4 series came from Nicholas Piggin, I've also made a few more minor changes and enhancements.

Because I have gone on different conferences talking about this work I've jotted down in a white-paper form what this is all about and I've used it as basis for a huge brush up on the documentation. I have not included the paper into the tree as I think the documentation now stands for itself. The paper may be useful for those wanted a huge verbose explanation to things with much more in depth analysis and review of history [2].

I've split up the linker table patches in two groups to make it easier to review, the first set (this) is for the kernel work, the second set is for the tools/ userspace sandbox. If you would like to review all the changes in git form you can yank them off of my linux-next 20161221-linker-tables-v5 branch on kernel.org [3], please however note that the last patch on that tree was *not* submitted upstream, it was used to force test 0-day and also Guenter's testbed to force-enable and run the tests. You can disregard that patch unless you also want to force test things :)

The biggest changes since v4 series worth noting:

o Ended up using two dots (..) to separate the new sections to avoid conflicts with compiler generated sections, so we have: .text..rng.*, .data..tbl.*, etc.

o Remove all the macro magic for section names. We now expect you to spell out each section manually. So no more SECTION_TEXT, for instance, for instance, we use just naked .text.

o Adds a section linker table selftest driver. I have a debug out of tree patch used which was applied when testing which force enables the driver to be built in. This has been successfully run time tested against the following architectures:

alpha arc arcv2 arm arm64 blackfin c6x
cris crisv32 frv h8300 hexagon i386 ia64
m32r m68k m68k_nommu metag microblaze mips_22 mips_24
mips_25 mn10300 nios2 openrisc parisc parisc64 powerpc
s390 score sh sparc32 sparc64 tile um
unicore32 x86_64 xtensa

The only architecture that was not tested was avr32 and that is because linux-next fails to compile on it. I'd like to greatly thank Guenter Roeck for his help with testing.

o A documentation revamp, to align what I hard originally written in the v4 series more in alignment with the the ELF specifications. Also properly document mark_rodata_ro().

o Recruited Josh Poimboeuf and hpa as co-mainters of the general section stuff. For section ranges and linker tables it will be both me and hpa reviewing things. At Plumbers I spoke with Arnd and he would prefer changes to go in through each respective tree that needs each change, so no new tree is created. We'll just review and Ack/nack changes.

Happy holidays, and may the force be with you all...

Oh and lastly, a quick summary of the gains of having an API for all this.

First the obvious gains:

o Allows us to just use plain C code to add new program specific ELF sections
o Makes it less error prone to add new sections

Then the not so obvious immediate gains:

o Helps simplify initialization code
o Helps optionally avoid code bit-rot (see commit "kbuild: enable option to force compile force-obj-y and force-lib-y)
o Enables link time ordering which can help make an extremely lightweight dependency annotations explicit (for this refer to the tools/linker-tables/ example where I've demo'd simplfying Xen PV init code, which has caused tons of regressions over time due to the lack of explicit dependency annotations due to the sloppy Xen PV entry path; this is not going away any time soon)

Not so obvious long term gains:

o Run time ordering customization are still possible (this is really long term but we already have one precedent in the kernel that does memmove() on entries on a section per some dependency heuristic.)
o May help prevent use of dead code by either free'ing / nop'ing, no exec or whatever sections which we know should definitely not run.
o Can easily increase the levels of initialization in the kernel without much changes (refer to tools/linker-tables/ for an example init with linker tables). I've seen a few cases where we've already run out of space to get init right in a few subsystems. This not only allows this but also allows subsystems to define their own custom levels of init if they wanted for their own things.
o Synthetic functions: enables custom C / asm functions which could help add new functionality (see synth_init_or() on tools/linker-tables/drivers/synth/main.c) I've been hinted this can help with RAID6 support
o Self modifying consts (see ps_shr() on tools/linker-tables/drivers/synth/main.c)

[0] https://lkml.kernel.org/r/[email protected]
[1] https://lkml.kernel.org/r/[email protected]
[2] http://drvbp1.linux-foundation.org/~mcgrof/papers/2016/12/21/linker-tables-20161221.pdf
[3] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linux-next.git/log/?h=20161221-linker-tables-v5

Luis R. Rodriguez (14):
generic-sections: add section core helpers
xtensa: skip adding literal when SORT() is used ranges.h: add helpers to build and identify Linux section ranges tables.h: add linker table support
kbuild: enable option to force compile force-obj-y and force-lib-y firmware/Makefile: force recompilation if makefile changes
firmware: port built-in section to linker table
jump_label: move guard #endif down where it belongs
jump_label: port __jump_table to linker tables
dynamic_debug: port to use linker tables
kprobes: move kprobe declarations to asm-generic/kprobes.h
kprobes: port .kprobes.text to section range
kprobes: port blacklist kprobes to linker table
lib: add linker tables test driver

 Documentation/index.rst                   |   1 +
 Documentation/kbuild/makefiles.txt        |  36 ++
 Documentation/sections/background.rst     | 105 ++++
 Documentation/sections/conf.py            |   4 +
 Documentation/sections/index.rst          |  19 +
 Documentation/sections/linker-tables.rst  | 227 +++++++++
 Documentation/sections/ranges.rst         |  74 +++
 Documentation/sections/section-core.rst   | 153 ++++++
 MAINTAINERS                               |  32 ++
 arch/alpha/include/asm/Kbuild             |   4 +
 arch/arc/include/asm/Kbuild               |   3 +
 arch/arc/include/asm/kprobes.h            |   6 +-
 arch/arc/kernel/vmlinux.lds.S             |   1 -
 arch/arm/include/asm/Kbuild               |   3 +
 arch/arm/include/asm/jump_label.h         |   6 +-
 arch/arm/include/asm/kprobes.h            |   4 +
 arch/arm/kernel/entry-armv.S              |   3 +-
 arch/arm/kernel/vmlinux-xip.lds.S         |   1 -
 arch/arm/kernel/vmlinux.lds.S             |   1 -
 arch/arm/probes/decode.h                  |   1 +
 arch/arm64/include/asm/Kbuild             |   3 +
 arch/arm64/include/asm/jump_label.h       |   6 +-
 arch/arm64/include/asm/kprobes.h          |   4 +
 arch/arm64/kernel/armv8_deprecated.c      |   1 +
 arch/arm64/kernel/insn.c                  |   1 +
 arch/arm64/kernel/probes/decode-insn.h    |   2 +
 arch/arm64/kernel/probes/kprobes.c        |   4 +-
 arch/arm64/kernel/vmlinux.lds.S           |   1 -
 arch/avr32/include/asm/Kbuild             |   3 +
 arch/avr32/include/asm/kprobes.h          |   7 +-
 arch/avr32/kernel/entry-avr32b.S          |  13 +-
 arch/avr32/kernel/vmlinux.lds.S           |   1 -
 arch/blackfin/include/asm/Kbuild          |   4 +
 arch/blackfin/kernel/vmlinux.lds.S        |   1 -
 arch/c6x/include/asm/Kbuild               |   3 +
 arch/c6x/include/asm/tables.h             |  26 +
 arch/c6x/kernel/vmlinux.lds.S             |   1 -
 arch/cris/include/asm/Kbuild              |   4 +
 arch/frv/include/asm/Kbuild               |   4 +
 arch/h8300/include/asm/Kbuild             |   4 +
 arch/hexagon/include/asm/Kbuild           |   4 +
 arch/hexagon/kernel/vmlinux.lds.S         |   1 -
 arch/ia64/include/asm/Kbuild              |   3 +
 arch/ia64/include/asm/kprobes.h           |  12 +-
 arch/ia64/kernel/jprobes.S                |   3 +-
 arch/ia64/kernel/vmlinux.lds.S            |   1 -
 arch/ia64/lib/flush.S                     |   6 +-
 arch/m32r/include/asm/Kbuild              |   4 +
 arch/m68k/include/asm/Kbuild              |   4 +
 arch/metag/include/asm/Kbuild             |   4 +
 arch/metag/kernel/vmlinux.lds.S           |   1 -
 arch/microblaze/include/asm/Kbuild        |   4 +
 arch/microblaze/kernel/vmlinux.lds.S      |   1 -
 arch/mips/include/asm/Kbuild              |   3 +
 arch/mips/include/asm/jump_label.h        |   6 +-
 arch/mips/include/asm/kprobes.h           |   6 +-
 arch/mips/kernel/vmlinux.lds.S            |   1 -
 arch/mn10300/include/asm/Kbuild           |   3 +
 arch/mn10300/include/asm/kprobes.h        |   7 +-
 arch/mn10300/kernel/vmlinux.lds.S         |   1 -
 arch/nios2/include/asm/Kbuild             |   4 +
 arch/nios2/kernel/vmlinux.lds.S           |   1 -
 arch/openrisc/include/asm/Kbuild          |   4 +
 arch/openrisc/kernel/vmlinux.lds.S        |   1 -
 arch/parisc/include/asm/Kbuild            |   4 +
 arch/parisc/kernel/vmlinux.lds.S          |   1 -
 arch/powerpc/include/asm/Kbuild           |   3 +
 arch/powerpc/include/asm/jump_label.h     |   8 +-
 arch/powerpc/include/asm/kprobes.h        |   3 +
 arch/powerpc/include/asm/ppc_asm.h        |   3 +-
 arch/powerpc/kernel/vmlinux.lds.S         |   3 +-
 arch/s390/include/asm/Kbuild              |   3 +
 arch/s390/include/asm/jump_label.h        |   6 +-
 arch/s390/include/asm/kprobes.h           |   7 +-
 arch/s390/kernel/entry.S                  |   5 +-
 arch/s390/kernel/kprobes.c                |   6 +-
 arch/s390/kernel/mcount.S                 |   3 +-
 arch/s390/kernel/vmlinux.lds.S            |   1 -
 arch/score/include/asm/Kbuild             |   4 +
 arch/score/kernel/vmlinux.lds.S           |   1 -
 arch/sh/include/asm/Kbuild                |   3 +
 arch/sh/include/asm/kprobes.h             |   5 +-
 arch/sh/kernel/vmlinux.lds.S              |   1 -
 arch/sparc/include/asm/Kbuild             |   3 +
 arch/sparc/include/asm/jump_label.h       |   6 +-
 arch/sparc/include/asm/kprobes.h          |  10 +-
 arch/sparc/kernel/vmlinux.lds.S           |   1 -
 arch/sparc/mm/ultra.S                     |   3 +-
 arch/tile/include/asm/Kbuild              |   3 +
 arch/tile/include/asm/jump_label.h        |   5 +-
 arch/tile/include/asm/kprobes.h           |   6 +-
 arch/tile/kernel/vmlinux.lds.S            |   1 -
 arch/um/include/asm/Kbuild                |   4 +
 arch/unicore32/include/asm/Kbuild         |   3 +
 arch/unicore32/include/asm/section-core.h |  19 +
 arch/x86/include/asm/Kbuild               |   3 +
 arch/x86/include/asm/asm.h                |   4 +-
 arch/x86/include/asm/jump_label.h         |  10 +-
 arch/x86/include/asm/kprobes.h            |   9 +-
 arch/x86/kernel/cpu/microcode/core.c      |   8 +-
 arch/x86/kernel/kprobes/core.c            |  11 +-
 arch/x86/kernel/vmlinux.lds.S             |   1 -
 arch/x86/tools/relocs.c                   |   4 +
 arch/xtensa/include/asm/Kbuild            |   4 +
 arch/xtensa/kernel/Makefile               |   8 +-
 drivers/base/firmware_class.c             |  12 +-
 firmware/Makefile                         |   6 +-
 include/asm-generic/kprobes.h             |  26 +
 include/asm-generic/ranges.h              |  93 ++++
 include/asm-generic/section-core.h        | 348 +++++++++++++
 include/asm-generic/sections.h            |   4 +-
 include/asm-generic/tables.h              |  48 ++
 include/asm-generic/vmlinux.lds.h         |  47 +-
 include/linux/compiler.h                  |   8 -
 include/linux/dynamic_debug.h             |   5 +-
 include/linux/init.h                      |  89 +++-
 include/linux/jump_label.h                |   8 +-
 include/linux/kprobes.h                   |  24 +-
 include/linux/ranges.h                    | 183 +++++++
 include/linux/sections.h                  |  87 ++++
 include/linux/tables.h                    | 683 +++++++++++++++++++++++++
 init/Kconfig                              |  22 +
 kernel/jump_label.c                       |  17 +-
 kernel/kprobes.c                          |  17 +-
 lib/Kconfig.debug                         |   6 +
 lib/Makefile                              |   1 +
 lib/dynamic_debug.c                       |  13 +-
 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 ++
 scripts/Makefile.build                    |   7 +-
 scripts/Makefile.clean                    |   2 +
 scripts/Makefile.lib                      |  11 +
 scripts/mod/modpost.c                     |   2 +-
 scripts/module-common.lds                 |   2 +
 scripts/recordmcount.c                    |   2 +-
 scripts/recordmcount.pl                   |   2 +-
 tools/objtool/special.c                   |   2 +-
 143 files changed, 3632 insertions(+), 200 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/linker-tables.rst
 create mode 100644 Documentation/sections/ranges.rst
 create mode 100644 Documentation/sections/section-core.rst
 create mode 100644 arch/c6x/include/asm/tables.h
 create mode 100644 arch/unicore32/include/asm/section-core.h
 create mode 100644 include/asm-generic/kprobes.h
 create mode 100644 include/asm-generic/ranges.h
 create mode 100644 include/asm-generic/section-core.h
 create mode 100644 include/asm-generic/tables.h
 create mode 100644 include/linux/ranges.h
 create mode 100644 include/linux/sections.h
 create mode 100644 include/linux/tables.h
 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
Signature · 1 line
2.10.1
author maintainer
#90 lore raw

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

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

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

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 compatiblity.

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 d0b2b50705bd..308826f5094b 100644
@@ -5422,6 +5422,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 860e440611c9..6111e1523750 100644
@@ -11,3 +11,4 @@ generic-y += preempt.h
 generic-y += sections.h
 generic-y += trace_clock.h
 generic-y += word-at-a-time.h
+generic-y += section-core.h
arch/m68k/include/asm/Kbuild +1 -0
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 45b0d6568270..a67d3177f3ca 100644
@@ -20,3 +20,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.10.1
author maintainer
#91 lore raw

PATCH v5 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.10.1
author maintainer
#92 lore raw

PATCH v5 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 betweeen 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.

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 308826f5094b..93bebccad674 100644
@@ -5422,6 +5422,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 6111e1523750..1c6504d29312 100644
@@ -12,3 +12,4 @@ generic-y += sections.h
 generic-y += trace_clock.h
 generic-y += word-at-a-time.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/m68k/include/asm/Kbuild +1 -0
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 a67d3177f3ca..288e21b64170 100644
@@ -21,3 +21,4 @@ generic-y += user.h
 generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/mn10300/include/asm/Kbuild +1 -0
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.10.1
author maintainer
#93 lore raw

PATCH v5 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.

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 93bebccad674..c57ba50e2348 100644
@@ -5405,6 +5405,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 1c6504d29312..24088f3c733c 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/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 288e21b64170..579f494914f5 100644
@@ -22,3 +22,4 @@ generic-y += word-at-a-time.h
 generic-y += xor.h
 generic-y += section-core.h
 generic-y += ranges.h
+generic-y += tables.h
arch/mn10300/include/asm/Kbuild +1 -0
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.10.1
#94 lore raw

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

Quoted 32 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.

+/**
+ * LINKTABLE_FOR_EACH - iterate through all entries within a linker table
+ *
+ * @pointer: entry pointer
+ * @tbl: linker table
+ *
+ * Example usage::
+ *
+ *   struct frobnicator *frob;
+ *
+ *   LINKTABLE_FOR_EACH(frob, frobnicator_fns) {
+ *     ...
+ *   }
+ */

(quoted diff) +2 -0
+
+#define LINKTABLE_FOR_EACH(pointer, tbl)				
Quoted 1 line

\

Hmm... SOMEONE LIKES CAPITAL LETTERS FOR everything, right? :-)

I would expect more standard
linktable_for_each()
macro

Same to the rest of similar macros.

Quoted 27 lines

+/**
+ * LINKTABLE_RUN_ERR - run each linker table entry func and return error if any
+ *
+ * @tbl: linker table
+ * @func: structure name for the function name we want to call.
+ * @args...: arguments to pass to func
+ *
+ * Example usage::
+ *
+ *   unsigned int err = LINKTABLE_RUN_ERR(frobnicator_fns, some_run,);
+ */
+#define LINKTABLE_RUN_ERR(tbl, func, args...)
\
+({
\

(quoted diff) +1 -0
+	size_t i;							

\

(quoted diff) +1 -0
+	int err = 0;							

\

(quoted diff) +1 -0
+	for (i = 0; !err && i < LINKTABLE_SIZE(tbl); i++)		

\

(quoted diff) +1 -0
+		err = (LINKTABLE_START(tbl)[i]).func (args);		

\

Review

Quoted 1 line
(quoted diff) +1 -0
+		err;							

Indentation here a bit confusing.

Quoted 2 lines

\
+})

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
author maintainer
#95 lore raw

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

Quoted 6 lines · Andy Shevchenko
Quoted 1 line · Luis R. Rodriguez

+#define LINKTABLE_FOR_EACH(pointer, tbl)

Hmm... SOMEONE LIKES CAPITAL LETTERS FOR everything, right? :-)

I would expect more standard linktable_for_each() macro

hpa had recommended this, if he prefers a lower case I can change that but I really do consider this bikeshedding.

Quoted 1 line

Same to the rest of similar macros.

Same answer here.

Quoted 26 lines
Quoted 24 lines

+/**
+ * LINKTABLE_RUN_ERR - run each linker table entry func and return error if any
+ *
+ * @tbl: linker table
+ * @func: structure name for the function name we want to call.
+ * @args...: arguments to pass to func
+ *
+ * Example usage::
+ *
+ *   unsigned int err = LINKTABLE_RUN_ERR(frobnicator_fns, some_run,);
+ */
+#define LINKTABLE_RUN_ERR(tbl, func, args...)
\
+({
\

(quoted diff) +1 -0
+	size_t i;							

\

(quoted diff) +1 -0
+	int err = 0;							

\

(quoted diff) +1 -0
+	for (i = 0; !err && i < LINKTABLE_SIZE(tbl); i++)		

\

(quoted diff) +1 -0
+		err = (LINKTABLE_START(tbl)[i]).func (args);		
Quoted 4 lines

Review

Quoted 2 lines

\

(quoted diff) +1 -0
+		err;							

Indentation here a bit confusing.

Ah yes, good catch, fixed.

Luis

#96 lore raw

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

Quoted 4 lines · Luis R. Rodriguez
Quoted 3 lines · Andy Shevchenko
Quoted 1 line · Luis R. Rodriguez

+#define LINKTABLE_FOR_EACH(pointer, tbl)

Quoted 8 lines
Quoted 3 lines

Hmm... SOMEONE LIKES CAPITAL LETTERS FOR everything, right? :-)

I would expect more standard linktable_for_each() macro

hpa had recommended this, if he prefers a lower case I can change that

but I really do consider this bikeshedding.

I don't think so:

$ git grep -n FOR_EACH | wc -l
    83
$ git grep -n for_each | wc -l
 23317
Signature · 7 lines
With Best Regards,
Andy Shevchenko

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

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

Quoted 12 lines · Andy Shevchenko
Quoted 9 lines · Luis R. Rodriguez
Quoted 6 lines · Andy Shevchenko
Quoted 1 line · Luis R. Rodriguez

+#define LINKTABLE_FOR_EACH(pointer, tbl)

Hmm... SOMEONE LIKES CAPITAL LETTERS FOR everything, right? :-)

I would expect more standard linktable_for_each() macro

hpa had recommended this, if he prefers a lower case I can change that

Quoted 7 lines
Quoted 1 line

but I really do consider this bikeshedding.

I don't think so:

$ git grep -n FOR_EACH | wc -l
    83
$ git grep -n for_each | wc -l
 23317

OK, would you also prefer if LINKTABLE_RUN_ERR() and LINKTABLE_RUN_ALL() were lowercase ? Or is that fine ? To be clear I'll leave upper case the declarers and defines.

Luis

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

#98 lore raw

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

Quoted 21 lines · Luis R. Rodriguez
Quoted 12 lines · Andy Shevchenko
Quoted 9 lines · Luis R. Rodriguez
Quoted 6 lines · Andy Shevchenko
Quoted 1 line · Luis R. Rodriguez

+#define LINKTABLE_FOR_EACH(pointer, tbl)

Hmm... SOMEONE LIKES CAPITAL LETTERS FOR everything, right? :-)

I would expect more standard linktable_for_each() macro

hpa had recommended this, if he prefers a lower case I can change that

Quoted 7 lines
Quoted 1 line

but I really do consider this bikeshedding.

I don't think so:

$ git grep -n FOR_EACH | wc -l
    83
$ git grep -n for_each | wc -l
 23317
Quoted 3 lines

OK, would you also prefer if LINKTABLE_RUN_ERR() and LINKTABLE_RUN_ALL() were lowercase ? Or is that fine ? To be clear I'll leave upper case the declarers and defines.

My understanding that macros to run code -- lower case, definitions -- upper case.

Thus, *_run_*() macros to lower.

Signature · 7 lines
With Best Regards,
Andy Shevchenko

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

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

Quoted 22 lines · Andy Shevchenko
Quoted 21 lines · Luis R. Rodriguez
Quoted 19 lines · Andy Shevchenko
Quoted 4 lines · Luis R. Rodriguez
Quoted 3 lines · Andy Shevchenko
Quoted 1 line · Luis R. Rodriguez

+#define LINKTABLE_FOR_EACH(pointer, tbl)

Quoted 8 lines
Quoted 3 lines

Hmm... SOMEONE LIKES CAPITAL LETTERS FOR everything, right? :-)

I would expect more standard linktable_for_each() macro

hpa had recommended this, if he prefers a lower case I can change that

but I really do consider this bikeshedding.

I don't think so:

$ git grep -n FOR_EACH | wc -l
    83
$ git grep -n for_each | wc -l
 23317
Quoted 8 lines
Quoted 3 lines

OK, would you also prefer if LINKTABLE_RUN_ERR() and LINKTABLE_RUN_ALL() were lowercase ? Or is that fine ? To be clear I'll leave upper case the declarers and defines.

My understanding that macros to run code -- lower case, definitions -- upper case.

Thus, *_run_*() macros to lower.

Very well, I've changed these, and since there were users I had to change a bit of the other patches so will send a v6 series follow up.

Luis

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

author maintainer
#100 lore raw

PATCH v5 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 71704159e90e..a80f4dd94659 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 223b734abccd..2faf4eee4c70 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.10.1
author maintainer
#101 lore raw

PATCH v5 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.10.1
author maintainer
#102 lore raw

PATCH v5 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.

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 c4bb2f7169f6..09133ef2c31b 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..94f2cf24d85d 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.10.1
author maintainer
#103 lore raw

PATCH v5 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.10.1
author maintainer
#104 lore raw

PATCH v5 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

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..d5c1067439ab 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.10.1
#105 lore raw

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

Quoted 23 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().

 {
  asm_volatile_goto("1:\n\t"
   WASM(nop) "\n\t"

(quoted diff) +1 -1
-		 ".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);

(quoted diff) +0 -0
@@ -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"

(quoted diff) +1 -1
-		 ".pushsection __jump_table,  \"aw\"\n\t"
+		 push_section_tbl_any(.data, __jump_table, aw)
Quoted 2 lines

   ".word 1b, %l[l_yes], %c0\n\t"
   ".popsection\n\t"

Does it make sense to introduce something like

#define pop_section_tbl ".popsection\n\t"
#define pop_section_tbl_any pop_section_tbl

?

Signature · 7 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy

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

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

Quoted 29 lines · Andy Shevchenko
Quoted 23 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().

 {
  asm_volatile_goto("1:\n\t"
   WASM(nop) "\n\t"

(quoted diff) +1 -1
-		 ".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);

(quoted diff) +0 -0
@@ -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"

(quoted diff) +1 -1
-		 ".pushsection __jump_table,  \"aw\"\n\t"
+		 push_section_tbl_any(.data, __jump_table, aw)
Quoted 2 lines

   ".word 1b, %l[l_yes], %c0\n\t"
   ".popsection\n\t"

Does it make sense to introduce something like

Quoted 2 lines

#define pop_section_tbl ".popsection\n\t"
#define pop_section_tbl_any pop_section_tbl

Absolutely ! However this would be an evolution, and I would much prefer to add this later as an atomic step later to enable other users to also be using this shared macro. I did not have an immediate need for a pop_section_tbl() macro as its not section specific.

Luis

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

author maintainer
#107 lore raw

PATCH v5 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.

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..23da6bcf2f95 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.10.1
author maintainer
#108 lore raw

PATCH v5 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

---
 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 +++----------------
 37 files changed, 122 insertions(+), 38 deletions(-)
 create mode 100644 include/asm-generic/kprobes.h
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 94b62c1fa4df..ae912304ed84 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 24088f3c733c..198ad591ab41 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/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.10.1
author maintainer
#109 lore raw

PATCH v5 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 04de188a36c9..b509a68af3c4 100644
@@ -21,6 +21,7 @@
 #include <asm/traps.h>
 #include <asm/uaccess.h>
 #include <asm/cpufeature.h>
+#include <asm/kprobes.h>
 
 #define CREATE_TRACE_POINTS
 #include "trace-events-emulation.h"
arch/arm64/kernel/probes/kprobes.c +2 -2
index 1decd2b2c730..7fbcfdf4e9e2 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 514f474249b0..bbf3b8acf5d3 100644
@@ -55,7 +55,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 fdb40424acfe..d49241fef651 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 d9d8d16b69db..b28be8dd14c6 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 d63095472ea9..c79f0b04383f 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.10.1
author maintainer
#110 lore raw

PATCH v5 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 c79f0b04383f..2bbfc30237ec 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 · 1 line
2.10.1
author maintainer
#111 lore raw

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

In reply to Luis R. Rodriguez

Add a test drivers for linker tables.

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 cb66a4648840..eca09bba2e8d 100644
@@ -1850,6 +1850,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 d15e235f72ea..4fce4aceb2a0 100644
@@ -55,6 +55,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.10.1
author maintainer
#112 lore raw

v6 cover linux: generalize sections, ranges and linker tables

In reply to Luis R. Rodriguez

This v6 addresses Andy Shevchenko's feedback from the v5 series [0] to use lowercase on a few of the tables.h macros. No other changes have been done to this series. As I had mentioned on the last cover-letter the v5 series had gone through a lot of testing both compile and run time, with the linktable test driver forced-enabled as a debug measure to try to capture errors as many architectures as possible:

    alpha      arc        arcv2       arm       arm64       blackfin    c6x                                                                                                     
    cris       crisv32    frv         h8300     hexagon     i386        ia64                                                                                                    
    m32r       m68k       m68k_nommu  metag     microblaze  mips_22     mips_24                                                                                                 
    mips_25    mn10300    nios2       openrisc  parisc      parisc64    powerpc                                                                                                 
    s390       score      sh          sparc32   sparc64     tile        um                                                                                                      
    unicore32  x86_64     xtensa                                                                                                                                                

The only architecture that was not tested was avr32 and that is because linux-next fails to compile on it. I'd like to greatly thank Guenter Roeck for his help with testing.

The debug patch which force enables the test driver is not submitted for upstream inclusion but is kept as part of the public tree for those curious, its the last patch [1]. This tree is based on linux-next tag next-20170109.

[0] https://lkml.kernel.org/r/[email protected]
[1] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linux-next.git/log/?h 170109-linker-tables-v6

Luis R. Rodriguez (14):
generic-sections: add section core helpers
xtensa: skip adding literal when SORT() is used ranges.h: add helpers to build and identify Linux section ranges tables.h: add linker table support
kbuild: enable option to force compile force-obj-y and force-lib-y firmware/Makefile: force recompilation if makefile changes
firmware: port built-in section to linker table
jump_label: move guard #endif down where it belongs
jump_label: port __jump_table to linker tables
dynamic_debug: port to use linker tables
kprobes: move kprobe declarations to asm-generic/kprobes.h
kprobes: port .kprobes.text to section range
kprobes: port blacklist kprobes to linker table
lib: add linker tables test driver

 Documentation/index.rst                   |   1 +
 Documentation/kbuild/makefiles.txt        |  36 ++
 Documentation/sections/background.rst     | 105 ++++
 Documentation/sections/conf.py            |   4 +
 Documentation/sections/index.rst          |  19 +
 Documentation/sections/linker-tables.rst  | 227 +++++++++
 Documentation/sections/ranges.rst         |  74 +++
 Documentation/sections/section-core.rst   | 153 ++++++
 MAINTAINERS                               |  32 ++
 arch/alpha/include/asm/Kbuild             |   4 +
 arch/arc/include/asm/Kbuild               |   3 +
 arch/arc/include/asm/kprobes.h            |   6 +-
 arch/arc/kernel/vmlinux.lds.S             |   1 -
 arch/arm/include/asm/Kbuild               |   3 +
 arch/arm/include/asm/jump_label.h         |   6 +-
 arch/arm/include/asm/kprobes.h            |   4 +
 arch/arm/kernel/entry-armv.S              |   3 +-
 arch/arm/kernel/vmlinux-xip.lds.S         |   1 -
 arch/arm/kernel/vmlinux.lds.S             |   1 -
 arch/arm/probes/decode.h                  |   1 +
 arch/arm64/include/asm/Kbuild             |   3 +
 arch/arm64/include/asm/jump_label.h       |   6 +-
 arch/arm64/include/asm/kprobes.h          |   4 +
 arch/arm64/kernel/armv8_deprecated.c      |   1 +
 arch/arm64/kernel/insn.c                  |   1 +
 arch/arm64/kernel/probes/decode-insn.h    |   2 +
 arch/arm64/kernel/probes/kprobes.c        |   4 +-
 arch/arm64/kernel/vmlinux.lds.S           |   1 -
 arch/avr32/include/asm/Kbuild             |   3 +
 arch/avr32/include/asm/kprobes.h          |   7 +-
 arch/avr32/kernel/entry-avr32b.S          |  13 +-
 arch/avr32/kernel/vmlinux.lds.S           |   1 -
 arch/blackfin/include/asm/Kbuild          |   4 +
 arch/blackfin/kernel/vmlinux.lds.S        |   1 -
 arch/c6x/include/asm/Kbuild               |   3 +
 arch/c6x/include/asm/tables.h             |  26 +
 arch/c6x/kernel/vmlinux.lds.S             |   1 -
 arch/cris/include/asm/Kbuild              |   4 +
 arch/frv/include/asm/Kbuild               |   4 +
 arch/h8300/include/asm/Kbuild             |   4 +
 arch/hexagon/include/asm/Kbuild           |   4 +
 arch/hexagon/kernel/vmlinux.lds.S         |   1 -
 arch/ia64/include/asm/Kbuild              |   3 +
 arch/ia64/include/asm/kprobes.h           |  12 +-
 arch/ia64/kernel/jprobes.S                |   3 +-
 arch/ia64/kernel/vmlinux.lds.S            |   1 -
 arch/ia64/lib/flush.S                     |   6 +-
 arch/m32r/include/asm/Kbuild              |   4 +
 arch/m68k/include/asm/Kbuild              |   4 +
 arch/metag/include/asm/Kbuild             |   4 +
 arch/metag/kernel/vmlinux.lds.S           |   1 -
 arch/microblaze/include/asm/Kbuild        |   4 +
 arch/microblaze/kernel/vmlinux.lds.S      |   1 -
 arch/mips/include/asm/Kbuild              |   3 +
 arch/mips/include/asm/jump_label.h        |   6 +-
 arch/mips/include/asm/kprobes.h           |   6 +-
 arch/mips/kernel/vmlinux.lds.S            |   1 -
 arch/mn10300/include/asm/Kbuild           |   3 +
 arch/mn10300/include/asm/kprobes.h        |   7 +-
 arch/mn10300/kernel/vmlinux.lds.S         |   1 -
 arch/nios2/include/asm/Kbuild             |   4 +
 arch/nios2/kernel/vmlinux.lds.S           |   1 -
 arch/openrisc/include/asm/Kbuild          |   4 +
 arch/openrisc/kernel/vmlinux.lds.S        |   1 -
 arch/parisc/include/asm/Kbuild            |   4 +
 arch/parisc/kernel/vmlinux.lds.S          |   1 -
 arch/powerpc/include/asm/Kbuild           |   3 +
 arch/powerpc/include/asm/jump_label.h     |   8 +-
 arch/powerpc/include/asm/kprobes.h        |   3 +
 arch/powerpc/include/asm/ppc_asm.h        |   3 +-
 arch/powerpc/kernel/vmlinux.lds.S         |   3 +-
 arch/s390/include/asm/Kbuild              |   3 +
 arch/s390/include/asm/jump_label.h        |   6 +-
 arch/s390/include/asm/kprobes.h           |   7 +-
 arch/s390/kernel/entry.S                  |   5 +-
 arch/s390/kernel/kprobes.c                |   6 +-
 arch/s390/kernel/mcount.S                 |   3 +-
 arch/s390/kernel/vmlinux.lds.S            |   1 -
 arch/score/include/asm/Kbuild             |   4 +
 arch/score/kernel/vmlinux.lds.S           |   1 -
 arch/sh/include/asm/Kbuild                |   3 +
 arch/sh/include/asm/kprobes.h             |   5 +-
 arch/sh/kernel/vmlinux.lds.S              |   1 -
 arch/sparc/include/asm/Kbuild             |   3 +
 arch/sparc/include/asm/jump_label.h       |   6 +-
 arch/sparc/include/asm/kprobes.h          |  10 +-
 arch/sparc/kernel/vmlinux.lds.S           |   1 -
 arch/sparc/mm/ultra.S                     |   3 +-
 arch/tile/include/asm/Kbuild              |   3 +
 arch/tile/include/asm/jump_label.h        |   5 +-
 arch/tile/include/asm/kprobes.h           |   6 +-
 arch/tile/kernel/vmlinux.lds.S            |   1 -
 arch/um/include/asm/Kbuild                |   4 +
 arch/unicore32/include/asm/Kbuild         |   3 +
 arch/unicore32/include/asm/section-core.h |  19 +
 arch/x86/include/asm/Kbuild               |   3 +
 arch/x86/include/asm/asm.h                |   4 +-
 arch/x86/include/asm/jump_label.h         |  10 +-
 arch/x86/include/asm/kprobes.h            |   9 +-
 arch/x86/kernel/cpu/microcode/core.c      |   8 +-
 arch/x86/kernel/kprobes/core.c            |  11 +-
 arch/x86/kernel/vmlinux.lds.S             |   1 -
 arch/x86/tools/relocs.c                   |   4 +
 arch/xtensa/include/asm/Kbuild            |   4 +
 arch/xtensa/kernel/Makefile               |   8 +-
 drivers/base/firmware_class.c             |  12 +-
 firmware/Makefile                         |   6 +-
 include/asm-generic/kprobes.h             |  26 +
 include/asm-generic/ranges.h              |  93 ++++
 include/asm-generic/section-core.h        | 348 +++++++++++++
 include/asm-generic/sections.h            |   4 +-
 include/asm-generic/tables.h              |  48 ++
 include/asm-generic/vmlinux.lds.h         |  47 +-
 include/linux/compiler.h                  |   8 -
 include/linux/dynamic_debug.h             |   5 +-
 include/linux/init.h                      |  89 +++-
 include/linux/jump_label.h                |   8 +-
 include/linux/kprobes.h                   |  24 +-
 include/linux/ranges.h                    | 183 +++++++
 include/linux/sections.h                  |  87 ++++
 include/linux/tables.h                    | 683 +++++++++++++++++++++++++
 init/Kconfig                              |  22 +
 kernel/jump_label.c                       |  17 +-
 kernel/kprobes.c                          |  17 +-
 lib/Kconfig.debug                         |   6 +
 lib/Makefile                              |   1 +
 lib/dynamic_debug.c                       |  13 +-
 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 ++
 scripts/Makefile.build                    |   7 +-
 scripts/Makefile.clean                    |   2 +
 scripts/Makefile.lib                      |  11 +
 scripts/mod/modpost.c                     |   2 +-
 scripts/module-common.lds                 |   2 +
 scripts/recordmcount.c                    |   2 +-
 scripts/recordmcount.pl                   |   2 +-
 tools/objtool/special.c                   |   2 +-
 143 files changed, 3632 insertions(+), 200 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/linker-tables.rst
 create mode 100644 Documentation/sections/ranges.rst
 create mode 100644 Documentation/sections/section-core.rst
 create mode 100644 arch/c6x/include/asm/tables.h
 create mode 100644 arch/unicore32/include/asm/section-core.h
 create mode 100644 include/asm-generic/kprobes.h
 create mode 100644 include/asm-generic/ranges.h
 create mode 100644 include/asm-generic/section-core.h
 create mode 100644 include/asm-generic/tables.h
 create mode 100644 include/linux/ranges.h
 create mode 100644 include/linux/sections.h
 create mode 100644 include/linux/tables.h
 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
Signature · 1 line
2.11.0
author maintainer
#113 lore raw

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

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

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

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 compatiblity.

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 c68a6bb17966..ae86136f4b9a 100644
@@ -5424,6 +5424,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 860e440611c9..6111e1523750 100644
@@ -11,3 +11,4 @@ generic-y += preempt.h
 generic-y += sections.h
 generic-y += trace_clock.h
 generic-y += word-at-a-time.h
+generic-y += section-core.h
arch/m68k/include/asm/Kbuild +1 -0
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 · 7 lines
2.11.0


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

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

Quoted 2 lines · Luis R. Rodriguez

Linux makes extensive use of custom ELF header sections, documentation for these are well scatterred. Unify this

is

Quoted 2 lines

documentation in a central place and provide helpers to build custom Linux sections.

This patch contains at least three logical changes and needs splitting:

* unify documentation
* adding helpers
* MAINTAINERS addition

Documentation and MAINTAINERS changes should go last in the patchset.

Accordingly, the huuge commit message below should be spread around those three patches.

Quoted 42 lines

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

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.

Quoted 7 lines

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 compatiblity.

v4:

o Port to shiny new sphinx documentation format

This looks like a 4th patch ontop of the unifying documentation one.

Quoted 11 lines

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.

...

Quoted 21 lines

+++ b/Documentation/sections/background.rst

Documentation/sections/background.rst new file +19 -0
@@ -0,0 +1,105 @@
+======================
+ELF section background
+======================
+
+About
+=====
+
+The purpose of this chapter is to help those not familiar with ELF to brush up
+the latest ELF specifications in order to help understand how Linux uses and
+defines its own ELF sections.
+
+Standardized ELF
+================
+
+The first publication documenting ELF was UNIX System Laboratories' (USL)
+*System V Release 4 Application Binary Interface* (`SRV4 ABI`_) specification.
+Originally ELF was only a small part of the SRV4 ABI, with time however new
+specifications only put focus on ELF, such was the case of the *TIS Portable
+Formats Specification version 1.2* (`TIS 1.2`_). As of TIS 1.2, ELF was

Documentation/sections/background.rst line 29

Quoted 10 lines
Documentation/sections/background.rst new file +10 -0
+supplemented with processor specific ELF addendums, available on the *Linux
+Foundation referenced specification page* (`LF ref page`_). The latest ELF
+specification is the *System V Application Binary Interface - DRAFT - 24 April
+2001* (`gabi4`_).
+
+.. _SRV4 ABI: http://www.sco.com/developers/devspecs/gabi41.pdf
+.. _TIS 1.2: https://refspecs.linuxbase.org/elf/elf.pdf
+.. _LF ref page: https://refspecs.linuxbase.org/
+.. _gabi4: https://refspecs.linuxbase.org/elf/gabi4+/contents.html
+

A pointer to the wikipedia page would suffice instead of us repeating ELF history here.

Documentation/sections/background.rst line 37

Quoted 8 lines
Documentation/sections/background.rst new file +8 -0
+ELF views on Linux
+==================
+
+There are two views which can be used for inspecting data in an ELF file, a
+Linking view, and an Execution view. A Section Header Table enables one to
+describe an object using the Linking view while a Program Header Table enables
+one to describe an object using the Execution view. The views are not mutually
+exclusive. For intance, vmlinux can be viewed under both views, ``readelf -S

s/intance/instance/

Documentation/sections/background.rst line 41

Quoted 4 lines
Documentation/sections/background.rst new file +4 -0
+vmlinux`` for the Linking view, and ``readelf -l vmlinux`` for the Execution
+view.  In Linux only the vmlinux file will have an Execution view, even modules
+lack an Execution view given that vmlinux is the only file that describes how
+the the kernel runs from the start.  All other Linux kernel object files have

s/the //

Documentation/sections/background.rst line 42

Quoted 1 line
Documentation/sections/background.rst new file +1 -0
+an available Linking view.

s/n available// - "have a Linking view" is fine.

Documentation/sections/background.rst

Quoted 5 lines
Documentation/sections/background.rst new file +5 -0
+
+Under the Linking view, the Section Header Table describes all available
+sections. The Section Header Table is an array of ELF section header data
+structures. If on a 32-bit system this is ``struct elf32_shd``, if on a 64-bit
+this is ``struct elf64_shdr``.

"If on ... if on" doesn't work as a sentence.

Quoted 1 line

Sections are only visible on object files that

s/on/in/

Documentation/sections/background.rst line 49

Quoted 2 lines
Documentation/sections/background.rst new file +2 -0
+have a Linking view, since all Linux kernel files have Linking view, all kernel
+objects have ELF sections.

Btw, that last sentence is kinda funny and not really needed. Or do you wanna say that everything-code is in a section?

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+Limitations on ELF sections

ELF sections limitations

Review

Quoted 3 lines

+===========================

(quoted diff) +2 -0
+
+We provide a summary on the limitations of ELF sections.

Kill that sentence.

Documentation/sections/background.rst line 56

Quoted 3 lines

Refer to the public

Documentation/sections/background.rst new file +2 -0
+ELF specifications for details. Note that 64-bit limitations may depend
+on processor specific section attributes to be used, refer to your processsor

"processsor" - the 's' button stuck? :-)

Quoted 1 line

+specification if unsure.

Better yet, kill that whole paragraph.

Review

Quoted 2 lines
(quoted diff) +2 -0
+
+Its worth ellaborating on the limitations on the name of an ELF section:

"elaborating"

Quoted 17 lines
Documentation/sections/background.rst new file +17 -0
+ELF section names are stored as strings as per the ELF specification, and
+as can be expected, these don't have explicit limitations. The implicit
+limitation then depends on the size of an ELF object file and ELF section.
+
+If using really large kernels or objects with large amounts of sections one
+would still need to be sure that ELF loader in charge of loading the Linux
+kernel is properly updated to handle coping with the latest ELF extensions.
+
+   .. flat-table:: Limitations on ELF Sections
+
+      * - Section attribute
+        - 32-bit
+        - 64-bit
+
+      * - ELF section name
+        - Size of an ELF section
+        - Size of an ELF section

Documentation/sections/background.rst line 86

Quoted 10 lines
Documentation/sections/background.rst new file +10 -0
+
+      * - Size of an ELF section
+        - 4 GiB
+        - 16 EiB
+
+      * - Max number of sections in an object file
+        - 4 GiEntries (4294967296)
+        - 16 EiEntries (18446744073709551616)
+
+Program specific ELF sections

Program-specific

Documentation/sections/background.rst line 90

Quoted 4 lines

+=============================

Documentation/sections/background.rst new file +3 -0
+
+The ELF specification allows for a section type to be specified as
+*Program specific section*, defined as ``SHT_PROGBITS``. This sections type

section

Quoted 1 line

+enables programs to customize sections for their own use. In assembly this

									^
									is
Quoted 1 line

+specified ``@progbits`` on most architectures, on ARM this is ``%progbits``.

	     ^		  ^

	     with the	  flag				s/this is/it is called/
Quoted 29 lines
Documentation/sections/background.rst new file +13 -0
+
+``SHT_PROGBITS`` is used by Linux for defining and using Linux ELF sections.
+
+Special ELF Sections
+====================
+
+The ELF specification defines *Special ELF Sections* on chapter 4 (`gabi4
+ch4`_). These are defined as sections which hold program and control
+information. Of these sections, a few have the section type as
+``SHT_PROGBITS``. This enables Linux to *further customize* use of the section
+beyond what the ELF specification suggests.
+
+.. _gabi4 ch4: https://refspecs.linuxbase.org/elf/gabi4+/ch4.sheader.html#special_sections
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 +0 -0
new file mode 100644
index 000000000000..f37511ef05e7

Documentation/sections/index.rst line 5

Quoted 5 lines
Documentation/sections/index.rst new file +5 -0
@@ -0,0 +1,17 @@
+=========================
+Linux Kernel ELF sections
+=========================
+
+This book documents the different ELF sections used on the Linux kernel.

in

Documentation/sections/index.rst line 11

Quoted 6 lines
Documentation/sections/index.rst new file +6 -0
+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.

s/few common a //

Quoted 6 lines
Documentation/sections/index.rst new file +6 -0
+
+.. toctree::
+   :maxdepth: 4
+
+   background
+   section-core

...

Quoted 6 lines
arch/unicore32/include/asm/section-core.h new file +0 -0
new file mode 100644
index 000000000000..0b9c68429a1a

arch/unicore32/include/asm/section-core.h line 8

Quoted 8 lines
arch/unicore32/include/asm/section-core.h new file +8 -0
@@ -0,0 +1,19 @@
+#ifndef __UNICORE_SECTION_CORE_ASM_H__
+#define __UNICORE_SECTION_CORE_ASM_H__
+/*
+ * Copyright (C) 2016 Luis R. Rodriguez <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of copyleft-next (version 0.3.1 or later) as published
+ * at http://copyleft-next.org/.

Isn't all kernel code GPLv2?

Quoted 35 lines
arch/unicore32/include/asm/section-core.h new file +11 -0
+ */
+
+/* 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 +0 -0
new file mode 100644
index 000000000000..bb16befc4251

include/asm-generic/section-core.h line 10

Quoted 10 lines
include/asm-generic/section-core.h new file +10 -0
@@ -0,0 +1,307 @@
+#ifndef _ASM_GENERIC_SECTION_CORE_H_
+#define _ASM_GENERIC_SECTION_CORE_H_
+/*
+ * Linux section core definitions
+ *
+ * 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/.

Ditto.

include/asm-generic/section-core.h

Quoted 6 lines
include/asm-generic/section-core.h new file +6 -0
+ */
+
+/**
+ * DOC: Linux ELF program specific sections
+ *
+ * Linux makes extensive use of ``SHT_PROGBITS`` to both extend use and definition
							     ^^^^^^^^^^^^^^^^^^^^^^^^

							     needs rewording
Quoted 2 lines

of *Special ELF Sections* (gabi4 ch4_) and to define its own
+ * sections. This chaper is dedicated to documenting Linux program specific

"chapter"

Please spellcheck the whole patchset before next submission.

Quoted 2 lines

+ * sections and helpers available to make use of these easier to implement and
+ * use.

Huh, come again? This sentence is funny.

include/asm-generic/section-core.h line 30

Quoted 10 lines

+ *
+ * .. _gabi4 ch4: https://refspecs.linuxbase.org/elf/gabi4+/ch4.sheader.html#special_sections
+ */

include/asm-generic/section-core.h new file +7 -0
+
+/**
+ * DOC: Linux linker script
+ *
+ * Linux uses a custom linker script to build the vmlinux binary, it uses it to
+ * strategically place and define Linux ELF sections.  Each architecture needs
+ * to implement its own linker script, it is expected to reside in

... script which is expected ...

Quoted 8 lines

+ * ``arch/$(ARCH)/kernel/vmlinux.lds.S``. Architecture Linux linker scripts in
+ * turn include and use definitions from ``include/asm-generic/vmlinux.lds.h``,
+ * as well as some helpers documented in this chapter.
+ *
+ * In assembly it is common practice to use dots (``.``) in labels to avoid
+ * clashes with C symbols. Similarly, a dot (``.``) can be part of a section
+ * name but not a C symbol. Historically then, two dots are used (``..``)
+ * have been used in linker scripts when adding program specific sections

are used .. have been used?

Quoted 1 line

+ * when there are concerns to avoid clashes with compiler generated sections.

This last sentence needs simplifying.

include/asm-generic/section-core.h line 47

Quoted 8 lines

+ */

include/asm-generic/section-core.h new file +7 -0
+
+/**
+ * DOC: Memory protection
+ *
+ * Linux allows architectures which support memory protection features to
+ * take advantage of them by letting architectures define and enable
+ * ``CONFIG_DEBUG_RODATA`` and implement a mark_rodata_ro() call.

Simplify: "Architectures with memory protection features can define and enable CONFIG_DEBUG_RODATA... "

Quoted 1 line

+ * mark_rodata_ro() can be used for instance to mark specific sections as

, for instance,

Quoted 4 lines

+ * read-only or non-executable.
+ *
+ * Linux typically follows a convention to have the .rodata ELF section follow
+ * after the .text ELF section, it does this to help architectures which

. It does this...

Quoted 63 lines

+ * support memory protection to mark both .text and .rodata as read-only in
+ * one shot.
+ *
+ * For more details refer to mark_rodata_ro().
+ */

include/asm-generic/section-core.h new file +58 -0
+
+/**
+ * DOC: .rodata
+ *
+ * ELF section used for data which must be protected from write access.
+ */
+
+/**
+ * DOC: .text
+ *
+ * ELF section name used for code (functions) used during regular
+ * kernel run time.
+ */
+
+/**
+ * DOC: .data
+ *
+ * ELF section used for read-write data.
+ */
+
+/**
+ * DOC: Linux init sections
+ *
+ * These sections are used for code and data structures used during boot or
+ * module initialization. On architectures that support it (x86, x86_64), all
+ * this code is freed up by the kernel right before the fist userspace init
+ * process is called when built-in to the kernel, and if modular it is freed
+ * after module initialization. Since the code is freed so early, in theory
+ * there should be no races against freeing this code with other CPUs. Init
+ * section code and data structures should never be exported with
+ * EXPORT_SYMBOL*() as the code will quickly become unavailable to the kernel
+ * after bootup.
+ */
+
+/**
+ * DOC: .init.text
+ *
+ * ELF section for code (functions) used only during boot or driver
+ * initialization.
+ *
+ */
+
+/**
+ * DOC: .init.data
+ *
+ * ELF section used for data structures used only during boot or driver
+ * initialization.
+ */
+
+/**
+ * DOC: .init.rodata
+ *
+ * ELF section used for read-only code (functions) used only during boot
+ * or driver initialization.
+ */
+
+/**
+ * DOC: .initcall

include/asm-generic/section-core.h line 125

Quoted 10 lines
include/asm-generic/section-core.h new file +10 -0
+ *
+ * ELF section used for subsystem init calls. There are init levels
+ * representing different functionality in the kernel. For more details
+ * refer to __define_initcall().
+ */
+
+/**
+ * DOC: Linux exit sections
+ *
+ * These sections are used to declare a functions and data structures which

s/a //

Quoted 30 lines

+ * are only required on exit, the function or data structure will be dropped
+ * if the code declaring this section is not compiled as a module on
+ * architectures that support this (x86, x86_64). There is no special case
+ * handling for this code when built-in to the kernel.
+ */

include/asm-generic/section-core.h new file +25 -0
+
+/**
+ * DOC: .exit.text
+ *
+ * ELF section used to for code (functions) used only during module unload.
+ */
+
+/**
+ * DOC: .exit.data
+ *
+ * ELF section used to for data structures used only during module
+ * unload.
+ */
+
+/**
+ * DOC: .exitcall.exit
+ *
+ * ELF section used for exit routines, order is important and maintained by
+ * link order.
+ */
+
+/**
+ * DOC: Linux references to init sections
+ *
+ * These sections are used to teach modpost to not warn about possible

include/asm-generic/section-core.h line 165

Quoted 10 lines
include/asm-generic/section-core.h new file +10 -0
+ * misuses of init section code from other sections. If you use this
+ * your use case should document why you are certain such use of init
+ * sectioned code is valid. For more details refer to ``include/linux/init.h``
+ * ``__ref``, ``__refdata``, and ``__refconst`` documentation.
+ */
+
+/**
+ * DOC: .ref.text
+ *
+ * ELF section used to annotate code (functions) which has been vetteed as

vetted?

include/asm-generic/section-core.h line 173

Quoted 8 lines

+ * valid for its reference or use of other code (functions) or data structures
+ * which are part of the init sections.
+ */

include/asm-generic/section-core.h new file +5 -0
+
+/**
+ * DOC: .ref.data
+ *
+ * ELF section used for data structures which have been vetteed for its

ditto.

include/asm-generic/section-core.h line 182

Quoted 9 lines

+ * reference or use of other code (functions) or data structures part of the
+ * init sections.
+ */

include/asm-generic/section-core.h new file +6 -0
+
+/**
+ * DOC: .ref.rodata
+ *
+ * ELF section used to annotate const code (functions) const data structures
+ * which has been vetteed for its reference or use of other code (functions)

ditto.

include/asm-generic/section-core.h line 186

Quoted 4 lines

+ * or data structures part of the init sections.
+ */

include/asm-generic/section-core.h new file +2 -0
+
+/* Can be used on foo.S for instance */

What does that comment mean?

include/asm-generic/section-core.h line 190

Quoted 4 lines
include/asm-generic/section-core.h new file +4 -0
+#ifndef __set_section_core_type
+# define __set_section_core_type(___section, ___core, ___name,		\
+				 ___level, ___flags, ___type)		\
+	.section ___section..___core.___name.___level, ___flags, ___type

Are you sure we need 4 levels of hierarchy?

If so, we should document what all those section, core, name and level mean and how the whole sections hierarchy is supposed to look like.

Quoted 36 lines
include/asm-generic/section-core.h new file +36 -0
+#endif
+
+#ifndef __set_section_core
+# define __set_section_core(___section, ___core, ___name, ___level, ___flags) \
+	.section ___section..___core.___name.___level, ___flags
+#endif
+
+#ifndef __push_section_core
+# define __push_section_core(__section, __core, __name, __level, __flags) \
+	.pushsection __section..__core.__name.__level, __flags
+#endif
+
+#ifdef __KERNEL__
+#include <linux/stringify.h>
+#endif
+
+#if defined(__ASSEMBLER__) || defined(__ASSEMBLY__)
+
+# ifndef LINKER_SCRIPT
+
+#  ifndef push_section_core
+#   define push_section_core(__section, __core, __name, __level, __flags) \
+	 __push_section_core(__section, __core, __name,			  \
+			     __level, __stringify(__flags))
+#  endif
+
+#  ifndef set_section_core
+#   define set_section_core(__section, __core, __name,			\
+			    __level, __flags)				\
+	__set_section_core(__section, __core, __name,			\
+			   __level, __stringify(__flags))
+#  endif
+
+#  ifndef set_section_core_type
+#   define set_section_core_type(__section, __core, __name,		\
+				 __level, __flags, __type)		\

include/asm-generic/section-core.h line 236

Quoted 10 lines
include/asm-generic/section-core.h new file +10 -0
+	__set_section_core_type(__section, __core, __name, __level,	\
+				__stringify(__flags), __type)
+#  endif
+
+# endif /* LINKER_SCRIPT */
+#else /* defined(__ASSEMBLER__) || defined(__ASSEMBLY__) */
+
+/*
+ * As per gcc's documentation a common asm separator is a new line followed
+ * by tab [0], it however seems possible to also just use a newline as its

. It, however, seems ...

Quoted 101 lines

+ * the most commonly empirically observed semantic and folks seem to agree
+ * this even works on S390. In case your architecture disagrees you may
+ * override this and define your own and keep the rest of the macros.
+ *
+ * [0] https://gcc.gnu.org/onlinedocs/gcc/Basic-Asm.html#Basic-Asm
+ */

include/asm-generic/section-core.h new file +65 -0
+# ifndef ASM_CMD_SEP
+#  define ASM_CMD_SEP	"\n"
+# endif
+
+# ifndef set_section_core
+#  define set_section_core(__section, __core, __name, __level, __flags)	\
+	__stringify(__set_section_core_type(__section, __core, __name,	\
+					    __level, __stringify(__flags))) \
+	ASM_CMD_SEP
+# endif
+
+/*
+ * Some architectures (arm, and avr32 are two examples on kprobes) seem
+ * currently explicitly specify the type [0] -- this can be any of the
+ * optional constants on ELF:
+ *
+ * @progbits - section contains data
+ * @nobits - section does not contain data (i.e., section only occupies space)
+ * @note - section contains data which is used by things other than the program
+ * @init_array - section contains an array of pointers to init functions
+ * @fini_array - section contains an array of pointers to finish functions
+ * @preinit_array - section contains an array of pointers to pre-init functions
+ *
+ * ARM requires % instead of @.
+ *
+ * At least as per nasm (x86/x86_64 only), in the absence of qualifiers the
+ * defaults are as follows:
+ *
+ * section .text    progbits  alloc   exec    nowrite  align=16
+ * section .rodata  progbits  alloc   noexec  nowrite  align=4
+ * section .lrodata progbits  alloc   noexec  nowrite  align=4
+ * section .data    progbits  alloc   noexec  write    align=4
+ * section .ldata   progbits  alloc   noexec  write    align=4
+ * section .bss     nobits    alloc   noexec  write    align=4
+ * section .lbss    nobits    alloc   noexec  write    align=4
+ * section .tdata   progbits  alloc   noexec  write    align=4    tls
+ * section .tbss    nobits    alloc   noexec  write    align=4    tls
+ * section .comment progbits  noalloc noexec  nowrite  align=1
+ * section other    progbits  alloc   noexec  nowrite  align=1
+ *
+ * gas should have sensible defaults for architectures...
+ *
+ * [0] http://www.nasm.us/doc/nasmdoc7.html
+ */
+# ifndef set_section_core_type
+#  define set_section_core_type(__section, __core, __name, __level,	\
+				__flags, __type)			\
+	__stringify(__set_section_core_type(__section, __core,		\
+					    __name, __level,		\
+					    __stringify(__flags),	\
+					    __type))			\
+	ASM_CMD_SEP
+# endif
+
+# ifndef push_section_core
+#  define push_section_core(__section, __core, __name,			\
+			    __level, __flags)				\
+	__stringify(__push_section_core(__section, __core,		\
+					__name,	__level,		\
+					__stringify(__flags)))		\
+	ASM_CMD_SEP
+# endif
+
+#endif /* defined(__ASSEMBLER__) || defined(__ASSEMBLY__) */
+#endif /* _ASM_GENERIC_SECTION_CORE_H_ */
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 +0 -0
index 885c3e6d0f9d..116e3262332a 100644

include/linux/init.h int __init init_rootfs(void); · line 137

Quoted 8 lines
include/linux/init.h +5 -0
@@ -130,6 +130,24 @@ int __init init_rootfs(void);
 extern bool rodata_enabled;
 #endif
 #ifdef CONFIG_DEBUG_RODATA
+/**
+ * mark_rodata_ro - implemement memory protection for ELF sections
+ *
+ * Architectures which support memory protection define a kernel configuration
+ * entry for CONFIG_DEBUG_RODATA,

That's just too many words for nothing. You can just as well say:

"Architectures which support memory protection enable CONFIG_DEBUG_RODATA and implement mark_rodata_ro()."

Quoted 3 lines

enable it in and implement mark_rodata_ro().
+ * mark_rodata_ro() should strive to adjust the .rodata and .text ELF sections
+ * with read-only memory protection to prevent modifications of these sections

"mark_rodata_ro() marks .rodata and .text section read-only..."

Simple.

Quoted 6 lines

+ * after bootup. It can also try to use memory protection to prevent execution
+ * on the .rodata ELF section.
+ *
+ * In order to help architectures set both .text and .rodata as read-only with
+ * memory protections in one shot Linux has typically followed the convention
+ * to have the .rodata ELF section follow the .text ELF section on the vmlinux

in

Quoted 4 lines

+ * linker script.
+ *
+ * Linux calls mark_rodata_ro() after freeing .init code and prior to calling
+ * the first init userspace process.

"first init userspace process" either say "prior to calling init" or "prior to calling the first userspace process" but both is jambalayed into something confusing.

include/linux/init.h extern bool initcall_debug; · line 164

Quoted 12 lines

+ */
void mark_rodata_ro(void);
#endif

include/linux/init.h +4 -0
@@ -140,25 +158,70 @@ extern bool initcall_debug;
 #endif
 
 #ifndef MODULE
+/**
+ * DOC: Initcall levels
+ *
+ * When Linux boots the kernel do_initcalls() iterates over each Linux

When Linux boots the kernel?!? You're joking, right?

Just do "During boot, do_initcalls() ..."

include/linux/init.h extern bool initcall_debug; · line 171

Quoted 7 lines
include/linux/init.h +7 -0
+ * initialization level ID and calls all routines embedded on each level ID.
+ * Prior to v2.5.2.3 Linux had only one init level onto which all init
+ * functions folded onto using __initcall(). After v2.5.2.4 Linux split up
+ * initcalls into 7 separate initcall subsection levels, each level describing
+ * different functionality part of the kernel (commit `9d6ba121b7e17085`_
+ * (v2.5.2.3 -> v2.5.2.4)). In order to remain backward compatible __initcall()
+ * calls were left mapped to device_initcall().

And why do we need all that git archeology here?

include/linux/init.h extern bool initcall_debug; · line 174

Quoted 2 lines
include/linux/init.h +2 -0
+ * Each init level consists of a dedicated ELF section, init functions are
+ * associated to an init level by linking it into the respective level's

with

include/linux/init.h extern bool initcall_debug; · line 178

Quoted 4 lines
include/linux/init.h +4 -0
+ * ELF section.
+ *
+ * Lower order init levels run prior to higher order init levels. Ordering
+ * inside each initcall level is determined by respective link order.

Those last two sentences are enough.

include/linux/init.h extern bool initcall_debug; · line 180

Quoted 2 lines
include/linux/init.h +2 -0
+ *
+ * .. _9d6ba121b7e17085: https://git.kernel.org/cgit/linux/kernel/git/history/history.git/commit/?id=9d6ba121b7e17085c95139233686b27a4d4c650e

That's one ugly footnote. Also, the git commit id suffices, you don't need the URL.

include/linux/init.h extern bool initcall_debug; · line 186

Quoted 12 lines
include/linux/init.h +3 -6
+ */
 
 #ifndef __ASSEMBLY__
 
-/*
- * initcalls are now grouped by functionality into separate
- * subsections. Ordering inside the subsections is determined
- * by link order. 
- * For backwards compatibility, initcall() puts the call in 
- * the device init subsection.
+/**
+ * __define_initcall - wrapper for definiting init levels
		       ()

also s/definiting/defining/

Also, this is not what __define_initcall() does. It is not defining init levels.

include/linux/init.h extern bool initcall_debug; · line 193

Quoted 13 lines
include/linux/init.h +5 -6
  *
- * The `id' arg to __define_initcall() is needed so that multiple initcalls
- * can point at the same handler without causing duplicate-symbol build errors.
+ * @fn: init routine
+ * @id: init level
  *
- * Initcalls are run by placing pointers in initcall sections that the
- * kernel iterates at runtime. The linker can do dead code / data elimination
- * and remove that completely, so the initcall sections have to be marked
- * as KEEP() in the linker script.
+ * Defines a kernel initialization level. A respective linker script entry
+ * is required to ensure the init level is accounted for and to ensure symbols
+ * exist for iterating over all functions in the init level. A init level

An

include/linux/init.h extern bool initcall_debug; · line 194

Quoted 1 line
include/linux/init.h +1 -0
+ * represents a series of functionality in the kernel.

That sounds yucky.

An init level is a bunch of functions which are called after init_level
- 1 and before init_level + 1.

Quoted 16 lines
include/linux/init.h +16 -0
+ *
+ * Ordering within an initialization level is determined by link order, so
+ * for instance if a Makefile had::
+ *
+ *	obj-y += foo.o
+ *	obj-y += bar.o
+ *
+ * And foo.c::
+ *
+ *	subsys_initcall(foo_init);
+ *
+ * And bar.c had::
+ *
+ *	subsys_initcall(bar_init);
+ *
+ * foo_init() would be called prior to bar_init().

include/linux/init.h extern bool initcall_debug;

Quoted 10 lines
include/linux/init.h +10 -0
+ *
+ * Note that @id in __define_initcall() also enables multiple initcalls
+ * to be created using the same handler for different init levels without
+ * causing duplicate-symbol build errors.
+ *
+ * Initcalls are run by placing start symbols to initcall levels inside ELF
+ * sections, the kernel in turn uses these symbols to iterate over each init
+ * level at runtime with do_initcall_level(). The end of each init level is
+ * marked by the subsequent's symbol's start address until we reach the symbol
+ * ``__initcall_end``.

Needlessly complex, simplify.

Quoted 2 lines

The linker can do dead code / data elimination and each
+ * init level start symbol could be removed completely in this process, to

. To <-- new sentence

Quoted 13 lines

+ * avoid this each init level start symbols must be marked as 'KEEP()' in the
+ * linker script to avoid any linker optimization heuristic on initcalls. */

include/linux/init.h +0 -1
-
 #define __define_initcall(fn, id) \
 	static initcall_t __initcall_##fn##id __used \
 	__attribute__((__section__(".initcall" #id ".init"))) = fn;
include/linux/sections.h new file +0 -0
new file mode 100644
index 000000000000..6771c727bcd1

include/linux/sections.h line 4

Quoted 4 lines
include/linux/sections.h new file +4 -0
@@ -0,0 +1,87 @@
+#ifndef _LINUX_SECTIONS_H
+#define _LINUX_SECTIONS_H
+/*
+ * Linux de-facto sections

Useless.

Quoted 7 lines
include/linux/sections.h new file +7 -0
+ *
+ * Copyright (C) 2016 Luis R. Rodriguez <[email protected]>
+ *
+ * This program is free software; you can redistribute it and/or modify it
+ * under the terms of copyleft-next (version 0.3.1 or later) as published
+ * at http://copyleft-next.org/.
+ */

include/linux/sections.h line 21

Quoted 10 lines
include/linux/sections.h new file +10 -0
+
+#include <asm/section-core.h>
+#include <linux/export.h>
+
+#ifndef __ASSEMBLY__
+
+/**
+ * DOC: Introduction
+ *
+ * Linux defines a set of common helpers which can be used to against its use
						      ^^^^^^^^^^^^^^^^^^^^^^^^^^

??

include/linux/sections.h line 22

Quoted 1 line
include/linux/sections.h new file +1 -0
+ * of standard or custom Linux sections, this section is dedicated to these

this section is talking about sections, that's too much.

include/linux/sections.h line 33

Quoted 11 lines
include/linux/sections.h new file +11 -0
+ * helpers.
+ */
+
+/**
+ * LINUX_SECTION_ALIGNMENT - get section alignment
+ *
+ * @name: section name
+ *
+ * Gives you the alignment for the section.
+ */
+#define LINUX_SECTION_ALIGNMENT(name)	__alignof__(*VMLINUX_SYMBOL(name))

Eeww, too long and it is a getter but doesn't have "GET" in its name.

How about GET_SECTION_ALIGN() ?

And what's with the "LINUX_" prefix - that's like useless use of screen real estate.

include/linux/sections.h line 36

Quoted 3 lines
include/linux/sections.h new file +3 -0
+
+/**
+ * LINUX_SECTION_START - get address of start of section

GET_SECTION_START() - get address of section start

include/linux/sections.h line 41

Quoted 5 lines
include/linux/sections.h new file +5 -0
+ *
+ * @name: section name
+ *
+ * This gives you the start address of the section.
+ * This should give you the address of the first entry.

Huh?

include/linux/sections.h line 44

Quoted 3 lines
include/linux/sections.h new file +3 -0
+ *
+ */
+#define LINUX_SECTION_START(name)	VMLINUX_SYMBOL(name)

Ditto.

Quoted 5 lines
include/linux/sections.h new file +5 -0
+
+/**
+ * LINUX_SECTION_END - get address of end of the section
+ *
+ * @name: section name

include/linux/sections.h line 59

Quoted 10 lines
include/linux/sections.h new file +10 -0
+ *
+ * This gives you the end address of the section.
+ * This should give you the address of the end of the
+ * section. This will match the start address if the
+ * section is empty.
+ */
+#define LINUX_SECTION_END(name)	VMLINUX_SYMBOL(name##__end)
+
+/**
+ * DECLARE_LINUX_SECTION - Declares a custom Linux section

DECLARE_SECTION() is perfectly fine IMO.

include/linux/sections.h line 71

Quoted 12 lines
include/linux/sections.h new file +12 -0
+ *
+ * @type: type of custom Linux section
+ * @name: custom section name
+ *
+ * Declares a read-write custom Linux section
+ */
+#define DECLARE_LINUX_SECTION(type, name)				\
+	 extern type VMLINUX_SYMBOL(name)[], \
+		     VMLINUX_SYMBOL(name##__end)[]
+
+/**
+ * DECLARE_LINUX_SECTION_RO - Declares a read-only custom Linux section

DECLARE_SECTION_RO()

Quoted 17 lines
include/linux/sections.h new file +16 -0
+ *
+ * @type: type of custom Linux section
+ * @name: custom section name
+ *
+ * Declares a read-only custom Linux section
+ */
+#define DECLARE_LINUX_SECTION_RO(type, name)				\
+	 extern const type VMLINUX_SYMBOL(name)[],			\
+			   VMLINUX_SYMBOL(name##__end)[]
+
+#define __SECTION_CORE(section, core, name, level)			\
+	#section ".." #core "." #name "." #level
+
+#endif /* __ASSEMBLY__ */
+
+#endif /* _LINUX_SECTIONS_H */
Signature · 4 lines
Regards/Gruss,
    Boris.

Good mailing practices for 400: avoid top-posting and trim the reply.
author maintainer
#115 lore raw

PATCH v6 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 · 7 lines
2.11.0


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

PATCH v6 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 betweeen 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.

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 ae86136f4b9a..c96ca032c276 100644
@@ -5424,6 +5424,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 6111e1523750..1c6504d29312 100644
@@ -12,3 +12,4 @@ generic-y += sections.h
 generic-y += trace_clock.h
 generic-y += word-at-a-time.h
 generic-y += section-core.h
+generic-y += ranges.h
arch/m68k/include/asm/Kbuild +1 -0
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 · 7 lines
2.11.0


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

PATCH v6 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.

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 +212 -0

212 lines not on this page · raw message

MAINTAINERS +10 -0
index c96ca032c276..bbf519da3a78 100644
@@ -5407,6 +5407,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 1c6504d29312..24088f3c733c 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/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 · 7 lines
2.11.0


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

PATCH v6 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 d0caacb4bc14..ce934ea6a7f1 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 · 7 lines
2.11.0


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

PATCH v6 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 · 7 lines
2.11.0


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

PATCH v6 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 · 7 lines
2.11.0


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

PATCH v6 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 · 7 lines
2.11.0


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

PATCH v6 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 · 7 lines
2.11.0


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

PATCH v6 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 · 7 lines
2.11.0


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

PATCH v6 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

---
 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 +++----------------
 37 files changed, 122 insertions(+), 38 deletions(-)
 create mode 100644 include/asm-generic/kprobes.h
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 94b62c1fa4df..ae912304ed84 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 24088f3c733c..198ad591ab41 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/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 · 7 lines
2.11.0


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

PATCH v6 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 ecf9298a12d4..35574b9fe6d4 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 · 7 lines
2.11.0


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

PATCH v6 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
#127 lore raw

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

In reply to Luis R. Rodriguez

Add a test drivers for linker tables.

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 5655bd95919a..8c99ee3c9fd7 100644
@@ -1827,6 +1827,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 94ed5cc4e89c..b5c5a7a9146c 100644
@@ -55,6 +55,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 · 7 lines
2.11.0


_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
Reviewed-by on the v6 series
#128 lore raw
In reply to Luis R. Rodriguez
Quoted 31 lines · Luis R. Rodriguez

This v6 addresses Andy Shevchenko's feedback from the v5 series [0] to use
lowercase on a few of the tables.h macros. No other changes have been done to
this series. As I had mentioned on the last cover-letter the v5 series had
gone through a lot of testing both compile and run time, with the linktable
test driver forced-enabled as a debug measure to try to capture errors as
many architectures as possible:

    alpha      arc        arcv2       arm       arm64       blackfin c6x

    cris       crisv32    frv         h8300     hexagon     i386 ia64

    m32r       m68k       m68k_nommu  metag     microblaze  mips_22 mips_24

    mips_25    mn10300    nios2       openrisc  parisc      parisc64 powerpc

    s390       score      sh          sparc32   sparc64     tile um

    unicore32  x86_64     xtensa

Quoted 5 lines

The only architecture that was not tested was avr32 and that is because
linux-next fails to compile on it. I'd like to greatly thank Guenter Roeck for
his help with testing.

We have a real board here. I would try to check if you provide a git url to your stuff.

I can confirm that breakage happened like in last couple of month. v4.10-rc3 can't be compiled either.

Quoted 11 lines

The debug patch which force enables the test driver is not submitted for
upstream inclusion but is kept as part of the public tree for those curious,
its the last patch [1]. This tree is based on linux-next tag next- 20170109.

[0] https://lkml.kernel.org/r/[email protected]
[1] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linux-
next.git/log/?h=20170109-linker-tables-v6

Series is fine to me

FWIW:

Quoted 187 lines

Luis R. Rodriguez (14):
  generic-sections: add section core helpers
  xtensa: skip adding literal when SORT() is used ranges.h: add helpers to build and identify Linux section ranges tables.h: add linker table support
  kbuild: enable option to force compile force-obj-y and force-lib-y firmware/Makefile: force recompilation if makefile changes
  firmware: port built-in section to linker table
  jump_label: move guard #endif down where it belongs
  jump_label: port __jump_table to linker tables
  dynamic_debug: port to use linker tables
  kprobes: move kprobe declarations to asm-generic/kprobes.h
  kprobes: port .kprobes.text to section range
  kprobes: port blacklist kprobes to linker table
  lib: add linker tables test driver

 Documentation/index.rst                   |   1 + Documentation/kbuild/makefiles.txt        |  36 ++ Documentation/sections/background.rst     | 105 ++++ Documentation/sections/conf.py            |   4 + Documentation/sections/index.rst          |  19 + Documentation/sections/linker-tables.rst  | 227 +++++++++ Documentation/sections/ranges.rst         |  74 +++ Documentation/sections/section-core.rst   | 153 ++++++ MAINTAINERS                               |  32 ++ arch/alpha/include/asm/Kbuild             |   4 + arch/arc/include/asm/Kbuild               |   3 + arch/arc/include/asm/kprobes.h            |   6 +- arch/arc/kernel/vmlinux.lds.S             |   1 - arch/arm/include/asm/Kbuild               |   3 + arch/arm/include/asm/jump_label.h         |   6 +- arch/arm/include/asm/kprobes.h            |   4 + arch/arm/kernel/entry-armv.S              |   3 +- arch/arm/kernel/vmlinux-xip.lds.S         |   1 - arch/arm/kernel/vmlinux.lds.S             |   1 - arch/arm/probes/decode.h                  |   1 + arch/arm64/include/asm/Kbuild             |   3 + arch/arm64/include/asm/jump_label.h       |   6 +- arch/arm64/include/asm/kprobes.h          |   4 + arch/arm64/kernel/armv8_deprecated.c      |   1 + arch/arm64/kernel/insn.c                  |   1 + arch/arm64/kernel/probes/decode-insn.h    |   2 + arch/arm64/kernel/probes/kprobes.c        |   4 +- arch/arm64/kernel/vmlinux.lds.S           |   1 - arch/avr32/include/asm/Kbuild             |   3 + arch/avr32/include/asm/kprobes.h          |   7 +- arch/avr32/kernel/entry-avr32b.S          |  13 +- arch/avr32/kernel/vmlinux.lds.S           |   1 - arch/blackfin/include/asm/Kbuild          |   4 + arch/blackfin/kernel/vmlinux.lds.S        |   1 - arch/c6x/include/asm/Kbuild               |   3 + arch/c6x/include/asm/tables.h             |  26 + arch/c6x/kernel/vmlinux.lds.S             |   1 - arch/cris/include/asm/Kbuild              |   4 + arch/frv/include/asm/Kbuild               |   4 + arch/h8300/include/asm/Kbuild             |   4 + arch/hexagon/include/asm/Kbuild           |   4 + arch/hexagon/kernel/vmlinux.lds.S         |   1 - arch/ia64/include/asm/Kbuild              |   3 + arch/ia64/include/asm/kprobes.h           |  12 +- arch/ia64/kernel/jprobes.S                |   3 +- arch/ia64/kernel/vmlinux.lds.S            |   1 - arch/ia64/lib/flush.S                     |   6 +- arch/m32r/include/asm/Kbuild              |   4 + arch/m68k/include/asm/Kbuild              |   4 + arch/metag/include/asm/Kbuild             |   4 + arch/metag/kernel/vmlinux.lds.S           |   1 - arch/microblaze/include/asm/Kbuild        |   4 + arch/microblaze/kernel/vmlinux.lds.S      |   1 - arch/mips/include/asm/Kbuild              |   3 + arch/mips/include/asm/jump_label.h        |   6 +- arch/mips/include/asm/kprobes.h           |   6 +- arch/mips/kernel/vmlinux.lds.S            |   1 - arch/mn10300/include/asm/Kbuild           |   3 + arch/mn10300/include/asm/kprobes.h        |   7 +- arch/mn10300/kernel/vmlinux.lds.S         |   1 - arch/nios2/include/asm/Kbuild             |   4 + arch/nios2/kernel/vmlinux.lds.S           |   1 - arch/openrisc/include/asm/Kbuild          |   4 + arch/openrisc/kernel/vmlinux.lds.S        |   1 - arch/parisc/include/asm/Kbuild            |   4 + arch/parisc/kernel/vmlinux.lds.S          |   1 - arch/powerpc/include/asm/Kbuild           |   3 + arch/powerpc/include/asm/jump_label.h     |   8 +- arch/powerpc/include/asm/kprobes.h        |   3 + arch/powerpc/include/asm/ppc_asm.h        |   3 +- arch/powerpc/kernel/vmlinux.lds.S         |   3 +- arch/s390/include/asm/Kbuild              |   3 + arch/s390/include/asm/jump_label.h        |   6 +- arch/s390/include/asm/kprobes.h           |   7 +- arch/s390/kernel/entry.S                  |   5 +- arch/s390/kernel/kprobes.c                |   6 +- arch/s390/kernel/mcount.S                 |   3 +- arch/s390/kernel/vmlinux.lds.S            |   1 - arch/score/include/asm/Kbuild             |   4 + arch/score/kernel/vmlinux.lds.S           |   1 - arch/sh/include/asm/Kbuild                |   3 + arch/sh/include/asm/kprobes.h             |   5 +- arch/sh/kernel/vmlinux.lds.S              |   1 - arch/sparc/include/asm/Kbuild             |   3 + arch/sparc/include/asm/jump_label.h       |   6 +- arch/sparc/include/asm/kprobes.h          |  10 +- arch/sparc/kernel/vmlinux.lds.S           |   1 - arch/sparc/mm/ultra.S                     |   3 +- arch/tile/include/asm/Kbuild              |   3 + arch/tile/include/asm/jump_label.h        |   5 +- arch/tile/include/asm/kprobes.h           |   6 +- arch/tile/kernel/vmlinux.lds.S            |   1 - arch/um/include/asm/Kbuild                |   4 + arch/unicore32/include/asm/Kbuild         |   3 + arch/unicore32/include/asm/section-core.h |  19 + arch/x86/include/asm/Kbuild               |   3 + arch/x86/include/asm/asm.h                |   4 +- arch/x86/include/asm/jump_label.h         |  10 +- arch/x86/include/asm/kprobes.h            |   9 +- arch/x86/kernel/cpu/microcode/core.c      |   8 +- arch/x86/kernel/kprobes/core.c            |  11 +- arch/x86/kernel/vmlinux.lds.S             |   1 - arch/x86/tools/relocs.c                   |   4 + arch/xtensa/include/asm/Kbuild            |   4 + arch/xtensa/kernel/Makefile               |   8 +- drivers/base/firmware_class.c             |  12 +- firmware/Makefile                         |   6 +- include/asm-generic/kprobes.h             |  26 + include/asm-generic/ranges.h              |  93 ++++ include/asm-generic/section-core.h        | 348 +++++++++++++ include/asm-generic/sections.h            |   4 +- include/asm-generic/tables.h              |  48 ++ include/asm-generic/vmlinux.lds.h         |  47 +- include/linux/compiler.h                  |   8 - include/linux/dynamic_debug.h             |   5 +- include/linux/init.h                      |  89 +++- include/linux/jump_label.h                |   8 +- include/linux/kprobes.h                   |  24 +- include/linux/ranges.h                    | 183 +++++++ include/linux/sections.h                  |  87 ++++ include/linux/tables.h                    | 683
+++++++++++++++++++++++++
 init/Kconfig                              |  22 + kernel/jump_label.c                       |  17 +- kernel/kprobes.c                          |  17 +- lib/Kconfig.debug                         |   6 + lib/Makefile                              |   1 + lib/dynamic_debug.c                       |  13 +- 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 ++ scripts/Makefile.build                    |   7 +- scripts/Makefile.clean                    |   2 + scripts/Makefile.lib                      |  11 + scripts/mod/modpost.c                     |   2 +- scripts/module-common.lds                 |   2 + scripts/recordmcount.c                    |   2 +- scripts/recordmcount.pl                   |   2 +- tools/objtool/special.c                   |   2 +-

 143 files changed, 3632 insertions(+), 200 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/linker-tables.rst create mode 100644 Documentation/sections/ranges.rst create mode 100644 Documentation/sections/section-core.rst create mode 100644 arch/c6x/include/asm/tables.h create mode 100644 arch/unicore32/include/asm/section-core.h create mode 100644 include/asm-generic/kprobes.h create mode 100644 include/asm-generic/ranges.h create mode 100644 include/asm-generic/section-core.h create mode 100644 include/asm-generic/tables.h create mode 100644 include/linux/ranges.h
 create mode 100644 include/linux/sections.h
 create mode 100644 include/linux/tables.h
 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

Signature · 7 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy

_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author maintainer
#129 lore raw
Quoted 7 lines · Andy Shevchenko
Quoted 3 lines · Luis R. Rodriguez

The only architecture that was not tested was avr32 and that is because linux-next fails to compile on it. I'd like to greatly thank Guenter Roeck for his help with testing.

We have a real board here. I would try to check if you provide a git url to your stuff.

I provided the git URL below, I will highlight it below again.

Quoted 2 lines

I can confirm that breakage happened like in last couple of month. v4.10-rc3 can't be compiled either.

You mean an avr32 board ?

Quoted 10 lines
Quoted 10 lines

The debug patch which force enables the test driver is not submitted for
upstream inclusion but is kept as part of the public tree for those curious,
its the last patch [1]. This tree is based on linux-next tag next- 20170109.

[0] https://lkml.kernel.org/r/[email protected]
[1] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linux-
next.git/log/?h=20170109-linker-tables-v6

Here is the git tree, note last patch is a debug patch which was not submitted, it force enables the debug test linktable patch, you do want that for your testing though.

Quoted 4 lines

Series is fine to me

FWIW:

Great thanks for the review!

Luis

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

#130 lore raw
In reply to Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Luis R. Rodriguez

The only architecture that was not tested was avr32 and that is because
linux-next fails to compile on it. I'd like to greatly thank Guenter Roeck for
his help with testing.

Quoted 6 lines

We have a real board here. I would try to check if you provide a git url
to your stuff.

I can confirm that breakage happened like in last couple of month. v4.10-rc3 can't be compiled either.

The culprit commit is

commit 3a0af8fd61f90920f6fa04e4f1e9a6a73c1b4fd2
Author: Thomas Graf <[email protected]>
Date:   Wed Nov 30 17:10:10 2016 +0100

    bpf: BPF for lightweight tunnel infrastructure

Signature · 6 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy - BIC 0357606-4 - Westendinkatu 7, 02160 Espoo
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
author maintainer
#131 lore raw
Quoted 16 lines · Andriy
Quoted 8 lines · Andy Shevchenko
Quoted 5 lines · Luis R. Rodriguez

The only architecture that was not tested was avr32 and that is because
linux-next fails to compile on it. I'd like to greatly thank Guenter Roeck for
his help with testing.

Quoted 6 lines

We have a real board here. I would try to check if you provide a git url
to your stuff.

I can confirm that breakage happened like in last couple of month. v4.10-rc3 can't be compiled either.

Quoted 7 lines

The culprit commit is

commit 3a0af8fd61f90920f6fa04e4f1e9a6a73c1b4fd2

Author: Thomas Graf <[email protected]>
Date:   Wed Nov 30 17:10:10 2016 +0100

bpf: BPF for lightweight tunnel infrastructure

OK I guess you folks can take it on in a separate thread, please feel free to Cc me.

Luis

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

#132 lore raw
In reply to Shevchenko, Andriy
Quoted 16 lines · Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
Quoted 6 lines · Luis R. Rodriguez

The only architecture that was not tested was avr32 and that is because
linux-next fails to compile on it. I'd like to greatly thank Guenter
Roeck for
his help with testing.

Quoted 6 lines

We have a real board here. I would try to check if you provide a git url
to your stuff.

I can confirm that breakage happened like in last couple of month. v4.10-rc3 can't be compiled either.

Quoted 8 lines

The culprit commit is

commit 3a0af8fd61f90920f6fa04e4f1e9a6a73c1b4fd2
Author: Thomas Graf <[email protected]>
Date:   Wed Nov 30 17:10:10 2016 +0100

    bpf: BPF for lightweight tunnel infrastructure

This makes modules closer to each other, so, net/socket.c:348: relocation truncated to fit: R_AVR32_11H_PCREL against `.text'+2930

But still the module is too big for AVR to do some jumps.

Here I stop investigating it. I had been proposed to get rid of avr32 completely, burden to support is just increasing (no Buildroot support, no Gcc support, what else do we need?) for no value.

net/core/Makefile +0 -0
index f6761b6e3b29..91b7d27bf2c6 100644
@@ -2,13 +2,13 @@

 # Makefile for the Linux networking core.
 #

-obj-y := sock.o request_sock.o skbuff.o datagram.o stream.o scm.o \
+obj-y := filter.o sock.o request_sock.o skbuff.o datagram.o stream.o scm.o \
         gen_stats.o gen_estimator.o net_namespace.o secure_seq.o flow_dissector.o

 obj-$(CONFIG_SYSCTL) += sysctl_net_core.o

 obj-y               += dev.o ethtool.o dev_addr_lists.o dst.o netevent.o \
-                       neighbour.o rtnetlink.o utils.o link_watch.o filter.o \
+                       neighbour.o rtnetlink.o utils.o link_watch.o \
                        sock_diag.o dev_ioctl.o tso.o sock_reuseport.o
 obj-$(CONFIG_XFRM) += flow.o

Signature · 2 lines
Andy Shevchenko <[email protected]>
Intel Finland Oy
author maintainer
#133 lore raw
Quoted 23 lines · Andy Shevchenko
Quoted 22 lines · Andy Shevchenko
Quoted 8 lines · Andy Shevchenko
Quoted 6 lines · Luis R. Rodriguez

The only architecture that was not tested was avr32 and that is because
linux-next fails to compile on it. I'd like to greatly thank Guenter
Roeck for
his help with testing.

Quoted 6 lines

We have a real board here. I would try to check if you provide a git url
to your stuff.

I can confirm that breakage happened like in last couple of month. v4.10-rc3 can't be compiled either.

The culprit commit is

commit 3a0af8fd61f90920f6fa04e4f1e9a6a73c1b4fd2
Author: Thomas Graf <[email protected]>
Date:   Wed Nov 30 17:10:10 2016 +0100

Quoted 8 lines
Quoted 2 lines

    bpf: BPF for lightweight tunnel infrastructure

This makes modules closer to each other, so, net/socket.c:348: relocation truncated to fit: R_AVR32_11H_PCREL against `.text'+2930

But still the module is too big for AVR to do some jumps.

Well I've reverted your patch and tested on avr32 and all tests worked successfully. Thanks to Guenter again for helping with his testbed once again!

Luis

author maintainer
#134 lore raw

v7 cover linux: generalize sections, ranges and linker tables

In reply to Luis R. Rodriguez

This v7 addresses spelling / minor checkpatch complaints, as requested. checkpatch still complains but the remaining complaints are not valid for the code in question.

A respective userspace sandbox for the kernel's tools/ follows this series. A branch based on linux-next tag next-20170113 is available [0], if you use that you should drop the last patch, that is used to force 0-day to test the linker table test driver enabled on all architectures.

Even though the changes made are minor I've re-tested this on all archs again, and all is good.

[0] https://git.kernel.org/cgit/linux/kernel/git/mcgrof/linux-next.git/log/?h=20170113-linker-tables-v7-try2

Luis R. Rodriguez (14):
generic-sections: add section core helpers
xtensa: skip adding literal when SORT() is used ranges.h: add helpers to build and identify Linux section ranges tables.h: add linker table support
kbuild: enable option to force compile force-obj-y and force-lib-y firmware/Makefile: force recompilation if makefile changes
firmware: port built-in section to linker table
jump_label: move guard #endif down where it belongs
jump_label: port __jump_table to linker tables
dynamic_debug: port to use linker tables
kprobes: move kprobe declarations to asm-generic/kprobes.h
kprobes: port .kprobes.text to section range
kprobes: port blacklist kprobes to linker table
lib: add linker tables test driver

 Documentation/index.rst                   |   1 +
 Documentation/kbuild/makefiles.txt        |  36 ++
 Documentation/sections/background.rst     | 105 ++++
 Documentation/sections/conf.py            |   4 +
 Documentation/sections/index.rst          |  19 +
 Documentation/sections/linker-tables.rst  | 227 +++++++++
 Documentation/sections/ranges.rst         |  74 +++
 Documentation/sections/section-core.rst   | 153 ++++++
 MAINTAINERS                               |  33 ++
 arch/alpha/include/asm/Kbuild             |   4 +
 arch/arc/include/asm/Kbuild               |   3 +
 arch/arc/include/asm/kprobes.h            |   6 +-
 arch/arc/kernel/vmlinux.lds.S             |   1 -
 arch/arm/include/asm/Kbuild               |   3 +
 arch/arm/include/asm/jump_label.h         |   6 +-
 arch/arm/include/asm/kprobes.h            |   4 +
 arch/arm/kernel/entry-armv.S              |   3 +-
 arch/arm/kernel/vmlinux-xip.lds.S         |   1 -
 arch/arm/kernel/vmlinux.lds.S             |   1 -
 arch/arm/probes/decode.h                  |   1 +
 arch/arm64/include/asm/Kbuild             |   3 +
 arch/arm64/include/asm/jump_label.h       |   6 +-
 arch/arm64/include/asm/kprobes.h          |   4 +
 arch/arm64/kernel/armv8_deprecated.c      |   1 +
 arch/arm64/kernel/insn.c                  |   1 +
 arch/arm64/kernel/probes/decode-insn.h    |   2 +
 arch/arm64/kernel/probes/kprobes.c        |   4 +-
 arch/arm64/kernel/vmlinux.lds.S           |   1 -
 arch/avr32/include/asm/Kbuild             |   3 +
 arch/avr32/include/asm/kprobes.h          |   7 +-
 arch/avr32/kernel/entry-avr32b.S          |  13 +-
 arch/avr32/kernel/vmlinux.lds.S           |   1 -
 arch/blackfin/include/asm/Kbuild          |   4 +
 arch/blackfin/kernel/vmlinux.lds.S        |   1 -
 arch/c6x/include/asm/Kbuild               |   3 +
 arch/c6x/include/asm/tables.h             |  26 +
 arch/c6x/kernel/vmlinux.lds.S             |   1 -
 arch/cris/include/asm/Kbuild              |   4 +
 arch/frv/include/asm/Kbuild               |   4 +
 arch/h8300/include/asm/Kbuild             |   4 +
 arch/hexagon/include/asm/Kbuild           |   4 +
 arch/hexagon/kernel/vmlinux.lds.S         |   1 -
 arch/ia64/include/asm/Kbuild              |   3 +
 arch/ia64/include/asm/kprobes.h           |  12 +-
 arch/ia64/kernel/jprobes.S                |   3 +-
 arch/ia64/kernel/vmlinux.lds.S            |   1 -
 arch/ia64/lib/flush.S                     |   6 +-
 arch/m32r/include/asm/Kbuild              |   4 +
 arch/m68k/include/asm/Kbuild              |   4 +
 arch/metag/include/asm/Kbuild             |   4 +
 arch/metag/kernel/vmlinux.lds.S           |   1 -
 arch/microblaze/include/asm/Kbuild        |   4 +
 arch/microblaze/kernel/vmlinux.lds.S      |   1 -
 arch/mips/include/asm/Kbuild              |   3 +
 arch/mips/include/asm/jump_label.h        |   6 +-
 arch/mips/include/asm/kprobes.h           |   6 +-
 arch/mips/kernel/vmlinux.lds.S            |   1 -
 arch/mn10300/include/asm/Kbuild           |   3 +
 arch/mn10300/include/asm/kprobes.h        |   7 +-
 arch/mn10300/kernel/vmlinux.lds.S         |   1 -
 arch/nios2/include/asm/Kbuild             |   4 +
 arch/nios2/kernel/vmlinux.lds.S           |   1 -
 arch/openrisc/include/asm/Kbuild          |   4 +
 arch/openrisc/kernel/vmlinux.lds.S        |   1 -
 arch/parisc/include/asm/Kbuild            |   4 +
 arch/parisc/kernel/vmlinux.lds.S          |   1 -
 arch/powerpc/include/asm/Kbuild           |   3 +
 arch/powerpc/include/asm/jump_label.h     |   8 +-
 arch/powerpc/include/asm/kprobes.h        |   3 +
 arch/powerpc/include/asm/ppc_asm.h        |   3 +-
 arch/powerpc/kernel/vmlinux.lds.S         |   3 +-
 arch/s390/include/asm/Kbuild              |   3 +
 arch/s390/include/asm/jump_label.h        |   6 +-
 arch/s390/include/asm/kprobes.h           |   7 +-
 arch/s390/kernel/entry.S                  |   5 +-
 arch/s390/kernel/kprobes.c                |   6 +-
 arch/s390/kernel/mcount.S                 |   3 +-
 arch/s390/kernel/vmlinux.lds.S            |   1 -
 arch/score/include/asm/Kbuild             |   4 +
 arch/score/kernel/vmlinux.lds.S           |   1 -
 arch/sh/include/asm/Kbuild                |   3 +
 arch/sh/include/asm/kprobes.h             |   5 +-
 arch/sh/kernel/vmlinux.lds.S              |   1 -
 arch/sparc/include/asm/Kbuild             |   3 +
 arch/sparc/include/asm/jump_label.h       |   6 +-
 arch/sparc/include/asm/kprobes.h          |  10 +-
 arch/sparc/kernel/vmlinux.lds.S           |   1 -
 arch/sparc/mm/ultra.S                     |   3 +-
 arch/tile/include/asm/Kbuild              |   3 +
 arch/tile/include/asm/jump_label.h        |   5 +-
 arch/tile/include/asm/kprobes.h           |   6 +-
 arch/tile/kernel/vmlinux.lds.S            |   1 -
 arch/um/include/asm/Kbuild                |   4 +
 arch/unicore32/include/asm/Kbuild         |   3 +
 arch/unicore32/include/asm/section-core.h |  19 +
 arch/x86/include/asm/Kbuild               |   3 +
 arch/x86/include/asm/asm.h                |   4 +-
 arch/x86/include/asm/jump_label.h         |  10 +-
 arch/x86/include/asm/kprobes.h            |   9 +-
 arch/x86/kernel/cpu/microcode/core.c      |   8 +-
 arch/x86/kernel/kprobes/core.c            |  11 +-
 arch/x86/kernel/vmlinux.lds.S             |   1 -
 arch/x86/tools/relocs.c                   |   4 +
 arch/xtensa/include/asm/Kbuild            |   4 +
 arch/xtensa/kernel/Makefile               |   8 +-
 drivers/base/firmware_class.c             |  12 +-
 firmware/Makefile                         |   6 +-
 include/asm-generic/kprobes.h             |  26 +
 include/asm-generic/ranges.h              |  93 ++++
 include/asm-generic/section-core.h        | 348 +++++++++++++
 include/asm-generic/sections.h            |   4 +-
 include/asm-generic/tables.h              |  48 ++
 include/asm-generic/vmlinux.lds.h         |  47 +-
 include/linux/compiler.h                  |   8 -
 include/linux/dynamic_debug.h             |   5 +-
 include/linux/init.h                      |  89 +++-
 include/linux/jump_label.h                |   8 +-
 include/linux/kprobes.h                   |  24 +-
 include/linux/ranges.h                    | 183 +++++++
 include/linux/sections.h                  |  87 ++++
 include/linux/tables.h                    | 683 +++++++++++++++++++++++++
 init/Kconfig                              |  22 +
 kernel/jump_label.c                       |  17 +-
 kernel/kprobes.c                          |  17 +-
 lib/Kconfig.debug                         |   6 +
 lib/Makefile                              |   1 +
 lib/dynamic_debug.c                       |  13 +-
 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 ++
 scripts/Makefile.build                    |   7 +-
 scripts/Makefile.clean                    |   2 +
 scripts/Makefile.lib                      |  11 +
 scripts/mod/modpost.c                     |   2 +-
 scripts/module-common.lds                 |   2 +
 scripts/recordmcount.c                    |   2 +-
 scripts/recordmcount.pl                   |   2 +-
 tools/objtool/special.c                   |   2 +-
 143 files changed, 3633 insertions(+), 200 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/linker-tables.rst
 create mode 100644 Documentation/sections/ranges.rst
 create mode 100644 Documentation/sections/section-core.rst
 create mode 100644 arch/c6x/include/asm/tables.h
 create mode 100644 arch/unicore32/include/asm/section-core.h
 create mode 100644 include/asm-generic/kprobes.h
 create mode 100644 include/asm-generic/ranges.h
 create mode 100644 include/asm-generic/section-core.h
 create mode 100644 include/asm-generic/tables.h
 create mode 100644 include/linux/ranges.h
 create mode 100644 include/linux/sections.h
 create mode 100644 include/linux/tables.h
 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
Signature · 1 line
2.11.0