linux: generalize sections, ranges and linker tables
Subsystems (32)
Luis R. Rodriguez
maintainerPATCH v4 6/6 tools: add userspace linker table sandbox
In reply to Luis R. RodriguezAdd a userspace sandbox to allow easy experimentation and test extensions with linker tables, section ranges and the new section core definitions.
The userspace sandbox tries to mimic the Linux kernel development flow as much as possible, it however relies on and uses libc. Support is currently only provided to x86_64.
Demo run:
cd tools/linker-tables
make clean; make;
./demo
Initializing x86 bare metal world
x86-init: Number of init entries: 8
Initializing memory ...
Completed initializing memory !
Initializing pci ...
PCI fixup size: 1
Demo: Using LINKTABLE_FOR_EACHfoo_fixup
Demo: Using LINKTABLE_RUN_ALLfoo_fixup
Completed initializing pci !
Number of init entries: 1
Initializing kprobes ...
== OK: test_kprobe_0001 within range!
== OK: test_kprobe_0002 not in range as expected! Completed initializing kprobes !
Initializing kasan ...
Early init for Kasan...
Completed initializing kasan !
Initializing beta ...
Completed initializing beta !
Initializing alpha ...
Completed initializing alpha !
Booting bare metal
Calling start_kernel()...
ACME: Initializing ...
ACME: Finished init ... !
Synthetics: synth_init_or(2) returns: 0xDEADBEEF
Synthetics: ps_shr(0xDEADBEEF, get_demo_shr) returns: 0x0000DEAD
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.
--- 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
@@ -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
@@ -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
@@ -35,12 +35,13 @@*/ /** -* DOC: Linker table provenance +* DOC: Linker table provenance and userspace testing * * The Linux implementation of linker tables was inspired by the iPXE linker * table's solution (iPXE commit 67a10ef000cb7 "[contrib] Add rom-o-matic to * contrib "[0]). To see how this code evolved refer to the out of tree -* userspace linker-table tree [1]. +* userspace linker-table tree [1]. Linux has a similar userspace application +* in tools/linker-tables/ to help more easily test adding new extensions. * * Contrary to iPXE's solution which strives to force compilation of * everything using linker tables, Linux's solution allows for developers to be
tools/Makefile +2 -1
@@ -19,6 +19,7 @@ help: @echo ' kvm_stat - top-like utility for displaying kvm statistics' @echo ' leds - LEDs tools' @echo ' lguest - a minimal 32-bit x86 hypervisor' + @echo ' linker-tables - userspace liker table sandbox and related tools' @echo ' net - misc networking tools' @echo ' perf - Linux performance measurement and analysis tool' @echo ' selftests - various kernel selftests'
@@ -86,7 +87,7 @@ tmon: FORCE freefall: FORCE $(call descend,laptop/$@) -all: acpi cgroup cpupower gpio hv firewire lguest \ +all: acpi cgroup cpupower gpio hv firewire lguest linker-tables \ perf selftests turbostat usb \ virtio vm net x86_energy_perf_policy \ tmon freefall objtool
tools/arch/x86/include/generated/asm/section-core.h new file +1 -0
@@ -0,0 +1 @@ +#include <asm-generic/section-core.h>
tools/arch/x86/include/generated/ranges.h new file +1 -0
@@ -0,0 +1 @@ +#include <asm-generic/ranges.h>
tools/arch/x86/include/generated/tables.h new file +1 -0
@@ -0,0 +1 @@ +#include <asm-generic/tables.h>
tools/include/asm-generic/ranges.h new file +93 -0
93 lines not on this page · raw message
tools/include/asm-generic/section-core.h new file +348 -0
348 lines not on this page · raw message
tools/include/asm-generic/tables.h new file +48 -0
48 lines not on this page · raw message
tools/include/linux/ranges.h new file +183 -0
183 lines not on this page · raw message
tools/include/linux/sections.h new file +87 -0
87 lines not on this page · raw message
tools/include/linux/string.h +1 -0
@@ -3,6 +3,7 @@#include <linux/types.h> /* for size_t */ +#include <string.h> void *memdup (const void *src,size_t len);
tools/include/linux/tables.h new file +684 -0
684 lines not on this page · raw message
tools/linker-tables/.gitignore new file +2 -0
@@ -0,0 +1,2 @@ +arch/x86/kernel/vmlinux.lds +demo
tools/linker-tables/Makefile new file +184 -0
184 lines not on this page · raw message
tools/linker-tables/README new file +114 -0
114 lines not on this page · raw message
tools/linker-tables/arch/x86/include/asm/asm.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef _ASM_X86_ASM_H + +#ifdef __ASSEMBLY__ +# define __ASM_FORM (x) x +# define __ASM_FORM_RAW (x) x +# define __ASM_FORM_COMMA (x) x, +#else +# define __ASM_FORM (x) " " #x " " +# define __ASM_FORM_RAW (x) #x +# define __ASM_FORM_COMMA (x) " " #x "," +#endif + +# define __ASM_SEL (a,b) __ASM_FORM(b) +# define __ASM_SEL_RAW (a,b) __ASM_FORM_RAW(b) +#define _ASM_PTR __ASM_SEL(.long, .quad) + +#endif /* _ASM_X86_ASM_H */
tools/linker-tables/arch/x86/include/asm/boot.h new file +1 -0
@@ -0,0 +1 @@ +extern struct boot_params boot_params;
tools/linker-tables/arch/x86/include/asm/bootparam.h new file +32 -0
@@ -0,0 +1,32 @@ +#ifndef __BOOTPARAM_H +#define __BOOTPARAM_H + +#include <linux/types.h> + +struct setup_header { +__u32 hardware_subarch; +} __attribute__((packed)); + +struct boot_params { +struct setup_header hdr; +} __attribute__((packed)); + +enum { +X86_SUBARCH_PC =0 , +X86_SUBARCH_LGUEST , +X86_SUBARCH_XEN , +X86_SUBARCH_INTEL_MID , +X86_SUBARCH_CE4100 , +X86_NR_SUBARCHS , +}; + +#define X86_SUBARCH_ALL_SUBARCHS \ + ( \ + BIT(X86_SUBARCH_PC) | \ + BIT(X86_SUBARCH_LGUEST) | \ + BIT(X86_SUBARCH_XEN) | \ + BIT(X86_SUBARCH_INTEL_MID) | \ + BIT(X86_SUBARCH_CE4100) \ + ) + +#endif /* __BOOTPARAM_H */
tools/linker-tables/arch/x86/include/asm/kprobes.h new file +7 -0
@@ -0,0 +1,7 @@ +#ifndef _SANDBOX_ASM_X86_KPROBES_H +#define _SANDBOX_ASM_X86_KPROBES_H + +/* This is all we need for the demo */ +#include <asm-generic/kprobes.h> + +#endif /* _SANDBOX_ASM_X86_KPROBES_H */
tools/linker-tables/arch/x86/include/asm/ps_const.h new file +23 -0
@@ -0,0 +1,23 @@ +#ifndef __X86_PS_CONST +#define __X86_PS_CONST + +#include <linux/stringify.h> +#include <linux/tables.h> +#include <asm/asm.h> + +#define ps_shr (in, _func) \ +({ \ + __typeof__(in) _count; \ + \ + asm volatile( \ + "shr %P[_in],%[_count]\n" \ + "1:\n" \ + push_section_tbl(.init.data, ps_set_const_table, 01,) \ + _ASM_PTR "1b-1, %P2, %P3\n" \ + ".popsection\n" \ + : [_count] "=g" (_count) \ + : [_in] "i" (in), "i" (SET_CONST_U8), "i" (_func)); \ + (_count); \ +}) + +#endif /* __X86_PS_CONST */
tools/linker-tables/arch/x86/include/asm/ranges.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _ASM_X86_RANGES_H +#define _ASM_X86_RANGES_H + +#include <asm-generic/ranges.h> + +#endif /* _ASM_X86_RANGES_H */
tools/linker-tables/arch/x86/include/asm/section-core.h new file +1 -0
@@ -0,0 +1 @@ +#include <asm-generic/section-core.h>
tools/linker-tables/arch/x86/include/asm/setup.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef __LINUX_X86_USER_SETUP_H +#define __LINUX_X86_USER_SETUP_H + +/* I'm lazy */ + +#endif /* __LINUX_X86_USER_SETUP_H */
tools/linker-tables/arch/x86/include/asm/tables.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _ASM_X86_TABLES_H +#define _ASM_X86_TABLES_H + +#include <asm-generic/tables.h> + +#endif /* _ASM_X86_RANGES_H */
tools/linker-tables/arch/x86/include/asm/x86.h new file +4 -0
@@ -0,0 +1,4 @@ +int startup_64 (void ); +int x86_64_start_reservations (void ); +void setup_arch (void ); +void late_init (void );
tools/linker-tables/arch/x86/include/asm/x86_init_fn.h new file +169 -0
169 lines not on this page · raw message
tools/linker-tables/arch/x86/kernel/alpha.c new file +10 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -0,0 +1,16 @@ +int demo_or_1 (int arg) +{ +switch (arg) { +case 1 : +return 0xDEA00000 ; +case 2 : +return 0X000D0000 ; +default : +return arg *2 ; + } +} + +int demo_or_2 (void ) +{ +return 0x0000BEEF ; +}
tools/linker-tables/drivers/synth/common.h new file +2 -0
@@ -0,0 +1,2 @@ +int demo_or_1 (int arg); +int demo_or_2 (void );
tools/linker-tables/drivers/synth/main.c new file +36 -0
@@ -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
@@ -0,0 +1,39 @@ +#include <asm/ranges.h> + + DEFINE_SECTION_RANGE(.text, synth_init_or) + + push_section_rng_level(.text, synth_init_or, "01", ) + /* err = 0; */ + pushq %rbp + movq %rsp,%rbp + pushq %rbx + xorq %rbx,%rbx + .popsection + + push_section_rng_level(.text, synth_init_or, "99", ) + /* return err; */ + movq %rbx,%rax + popq %rbx + popq %rbp + retq + .popsection + + push_section_rng_level(.text, synth_init_or, "50", ) + /* err |= demo_or_1(1); */ + movl $1,%edi + call demo_or_1 + orq %rax,%rbx + .popsection + + push_section_rng_level(.text, synth_init_or, "50", ) + /* err |= demo_or_1(2); */ + movl $2,%edi + call demo_or_1 + orq %rax,%rbx + .popsection + + push_section_rng_level(.text, synth_init_or, "50", ) + /* err |= demo_or_2(); */ + call demo_or_2 + orq %rax,%rbx + .popsection
tools/linker-tables/drivers/synth/synth.h new file +2 -0
@@ -0,0 +1,2 @@ +/* Synthetic demos go here */ +int synth_init_or (int arg);
tools/linker-tables/drivers/xen-driver.c new file +12 -0
@@ -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
@@ -0,0 +1,26 @@ +#ifndef _SANDBOX_ASM_GENERIC_KPROBES_H +#define _SANDBOX_ASM_GENERIC_KPROBES_H + +#if defined(__KERNEL__) && !defined(__ASSEMBLY__) +#ifdef CONFIG_KPROBES +#include <linux/tables.h> +#include <asm/ranges.h> +/* +* Blacklist ganerating macro. Specify functions which is not probed +* by using this macro. +*/ +# define __NOKPROBE_SYMBOL (fname) \ +static LINKTABLE_INIT_DATA(_kprobe_blacklist, all) \ + _kbl_addr_##fname = (unsigned long)fname; +# define NOKPROBE_SYMBOL (fname) __NOKPROBE_SYMBOL(fname) +/* Use this to forbid a kprobes attach on very low level functions */ +# define __kprobes __LINUX_RANGE(.text, kprobes) +# define nokprobe_inline __always_inline +#else +# define NOKPROBE_SYMBOL (fname) +# define __kprobes +# define nokprobe_inline inline +#endif +#endif /* defined(__KERNEL__) && !defined(__ASSEMBLY__) */ + +#endif /* _SANDBOX_ASM_GENERIC_KPROBES_H */
tools/linker-tables/include/linux/bitops.h new file +6 -0
@@ -0,0 +1,6 @@ +#ifndef _LINUX_BITOPS_H +#define _LINUX_BITOPS_H + +#define BIT (nr) (1UL << (nr)) + +#endif /* _LINUX_BITOPS_H */
tools/linker-tables/include/linux/init.h new file +40 -0
@@ -0,0 +1,40 @@ +#ifndef _SANDBOX_LINUX_INIT_H +#define _SANDBOX_LINUX_INIT_H + +#include_next <linux/init.h> +#include <linux/types.h> +#include <linux/sections.h> + +#define __init __section(.init.text) +#define __exit __section(.exit.text) + +#ifndef __ASSEMBLY__ +#include <linux/tables.h> +typedef int (*initcall_t )(void ); +typedef void (*exitcall_t )(void ); + +DECLARE_LINKTABLE (initcall_t, init_calls); +DECLARE_LINKTABLE (exitcall_t, exit_calls); + +#define __define_initcall (fn, id) \ + static LINKTABLE_INIT_DATA(init_calls, id) \ + __initcall_##fn##id = fn + +#define pure_initcall (fn) __define_initcall(fn, 0) +#define core_initcall (fn) __define_initcall(fn, 1) +#define postcore_initcall (fn) __define_initcall(fn, 2) +#define arch_initcall (fn) __define_initcall(fn, 3) +#define subsys_initcall (fn) __define_initcall(fn, 4) +#define fs_initcall (fn) __define_initcall(fn, 5) +#define device_initcall (fn) __define_initcall(fn, 6) +#define late_initcall (fn) __define_initcall(fn, 7) + +#define __initcall (fn) device_initcall(fn) + +#define __exitcall (fn) \ + static LINKTABLE_INIT_DATA(exit_calls, any) \ + __exitcall_##fn = fn; + +#endif + +#endif /* _SANDBOX_LINUX_INIT_H */
tools/linker-tables/include/linux/kasan.h new file +5 -0
@@ -0,0 +1,5 @@ +#include <linux/types.h> + +void kasan_early_init (void ); +int kasan_init (void ); +bool is_kasan_setup (void );
tools/linker-tables/include/linux/kernel.h new file +2 -0
@@ -0,0 +1,2 @@ +#include_next <linux/kernel.h> +#include <linux/printk.h>
tools/linker-tables/include/linux/kprobes.h new file +11 -0
@@ -0,0 +1,11 @@ +#ifndef _SANDBOX_LINUX_KPROBES_H +#define _SANDBOX_LINUX_KPROBES_H + +#include <asm/kprobes.h> +#include <linux/ranges.h> + +#ifdef CONFIG_KPROBES +DECLARE_SECTION_RANGE (kprobes); +#endif + +#endif /* _SANDBOX_LINUX_KPROBES_H */
tools/linker-tables/include/linux/module.h new file +14 -0
@@ -0,0 +1,14 @@ +#ifndef _LINUX_MODULE_H +#define _LINUX_MODULE_H + +#include <linux/init.h> + +#define module_init (x) __initcall(x); +#define module_exit (x) __exitcall(x); + +struct module { +int (*init)(void ); +void (*exit)(void ); +}; + +#endif /* _LINUX_MODULE_H */
tools/linker-tables/include/linux/mutex.h new file +17 -0
@@ -0,0 +1,17 @@ +#ifndef __LINUX_MUTEX_H +#define __LINUX_MUTEX_H + +#include <sys/types.h> +#include <linux/sched.h> +#include <pthread.h> + +struct mutex { +pthread_mutex_t lock; +}; + +void mutex_init (struct mutex *lock); +void mutex_destroy (struct mutex *lock); +void mutex_lock (struct mutex *lock); +void mutex_unlock (struct mutex *lock); + +#endif /* __LINUX_MUTEX_H */
tools/linker-tables/include/linux/pci.h new file +7 -0
@@ -0,0 +1,7 @@ +#include <linux/types.h> + +struct pci_fixup { +void (*hook)(void ); +}; + +bool detect_pci (void );
tools/linker-tables/include/linux/printk.h new file +26 -0
@@ -0,0 +1,26 @@ +#ifndef _SANDBOX_KERNEL_PRINTK +#define _SANDBOX_KERNEL_PRINTK + +#ifdef __KERNEL__ + +#include <stdio.h> + +#ifndef pr_fmt +#define pr_fmt (fmt) fmt +#endif + +#ifndef pr_info +#define pr_info (fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__) +#endif + +#ifndef pr_err +#define pr_err (fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__) +#endif + +#ifndef pr_debug +#define pr_debug (fmt, ...) printf(pr_fmt(fmt), ##__VA_ARGS__) +#endif + +#endif /* __KERNEL__ */ + +#endif /* _SANDBOX_KERNEL_PRINTK */
tools/linker-tables/include/linux/ps_const.h new file +46 -0
46 lines not on this page · raw message
tools/linker-tables/include/linux/sched.h new file +9 -0
@@ -0,0 +1,9 @@ +#ifndef _LINUX_SCHED_H +#define _LINUX_SCHED_H + +#include <linux/ranges.h> + +DECLARE_SECTION_RANGE (sched_text); +#define __sched __LINUX_RANGE(.text, sched_text) + +#endif /* _LINUX_SCHED_H */
tools/linker-tables/include/linux/spinlock.h new file +13 -0
@@ -0,0 +1,13 @@ +#ifndef __LINUX_SPINLOCK_H +#define __LINUX_SPINLOCK_H + +#include <pthread.h> + +#define spinlock_t pthread_spinlock_t + +void spin_lock_init (spinlock_t *lock); +void spin_lock_destroy (spinlock_t *lock); +void spin_lock (spinlock_t *lock); +void spin_unlock (spinlock_t *lock); +
Lines of this file are not shown. View the raw message.
tools/linker-tables/include/linux/start_kernel.h new file +1 -0
Lines of this file are not shown. View the raw message.
tools/linker-tables/include/linux/types.h new file +13 -0
Lines of this file are not shown. View the raw message.
tools/linker-tables/include/linux/workqueue.h new file +51 -0
51 lines not on this page · raw message
tools/linker-tables/include/xen/xen.h new file +4 -0
Lines of this file are not shown. View the raw message.
tools/linker-tables/kernel/locking/mutex.c new file +28 -0
Lines of this file are not shown. View the raw message.
tools/linker-tables/kernel/locking/spinlock.c new file +26 -0
Lines of this file are not shown. View the raw message.
tools/linker-tables/kernel/main.c new file +32 -0
Lines of this file are not shown. View the raw message.
tools/linker-tables/kernel/workqueue.c new file +43 -0
43 lines not on this page · raw message
tools/linker-tables/lib/string.c new file +26 -0
Lines of this file are not shown. View the raw message.
tools/linker-tables/pci-quirks.c new file +14 -0
Lines of this file are not shown. View the raw message.
The rest of this diff is not shown. View the raw message.
Signature · 1 line
2.11.0
Part of the diff is not shown here. View the raw message.
Greg KH
maintainerRe: [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: UsingLINKTABLE_FOR_EACHfoo_fixup
Demo: UsingLINKTABLE_RUN_ALLfoo_fixup
Completed initializing pci !
Number of init entries: 1
Initializing kprobes ...
== OK:test_kprobe_0001within range!
== OK:test_kprobe_0002not 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
Callingstart_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
Luis R. Rodriguez
maintainerv5 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
Luis R. Rodriguez
maintainerPATCH 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -62,3 +62,4 @@ generic-y += user.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/cris/include/asm/Kbuild +1 -0
@@ -45,3 +45,4 @@ generic-y += types.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/frv/include/asm/Kbuild +1 -0
@@ -8,3 +8,4 @@ generic-y += mm-arch-hooks.h generic-y += preempt.h generic-y += trace_clock.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/h8300/include/asm/Kbuild +1 -0
@@ -75,3 +75,4 @@ generic-y += unaligned.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/hexagon/include/asm/Kbuild +1 -0
@@ -60,3 +60,4 @@ generic-y += unaligned.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/ia64/include/asm/Kbuild +1 -0
@@ -9,3 +9,4 @@ generic-y += preempt.h generic-y += trace_clock.h generic-y += vtime.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/m32r/include/asm/Kbuild +1 -0
@@ -11,3 +11,4 @@ generic-y += preempt.h generic-y += sections.h generic-y += trace_clock.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/m68k/include/asm/Kbuild +1 -0
@@ -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
@@ -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
@@ -11,3 +11,4 @@ generic-y += preempt.h generic-y += syscalls.h generic-y += trace_clock.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/mips/include/asm/Kbuild +1 -0
@@ -20,3 +20,4 @@ generic-y += 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
@@ -10,3 +10,4 @@ generic-y += preempt.h generic-y += sections.h generic-y += trace_clock.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/nios2/include/asm/Kbuild +1 -0
@@ -63,3 +63,4 @@ generic-y += user.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/openrisc/include/asm/Kbuild +1 -0
@@ -71,3 +71,4 @@ generic-y += user.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/parisc/include/asm/Kbuild +1 -0
@@ -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
@@ -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
@@ -8,3 +8,4 @@ generic-y += mm-arch-hooks.h generic-y += preempt.h generic-y += trace_clock.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/score/include/asm/Kbuild +1 -0
@@ -14,3 +14,4 @@ generic-y += trace_clock.h generic-y += xor.h generic-y += serial.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/sh/include/asm/Kbuild +1 -0
@@ -39,3 +39,4 @@ generic-y += termios.h generic-y += trace_clock.h generic-y += ucontext.h generic-y += xor.h +generic-y += section-core.h
arch/sparc/include/asm/Kbuild +1 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Luis R. Rodriguez
maintainerPATCH v5 2/14 xtensa: skip adding literal when SORT() is used
In reply to Luis R. RodriguezWhen 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
@@ -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
Luis R. Rodriguez
maintainerPATCH v5 3/14 ranges.h: add helpers to build and identify Linux section ranges
In reply to Luis R. RodriguezSection 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -63,3 +63,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/cris/include/asm/Kbuild +1 -0
@@ -46,3 +46,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/frv/include/asm/Kbuild +1 -0
@@ -9,3 +9,4 @@ generic-y += preempt.h generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/h8300/include/asm/Kbuild +1 -0
@@ -76,3 +76,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/hexagon/include/asm/Kbuild +1 -0
@@ -61,3 +61,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/ia64/include/asm/Kbuild +1 -0
@@ -10,3 +10,4 @@ generic-y += trace_clock.h generic-y += vtime.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/m32r/include/asm/Kbuild +1 -0
@@ -12,3 +12,4 @@ generic-y += sections.h generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/m68k/include/asm/Kbuild +1 -0
@@ -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
@@ -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
@@ -12,3 +12,4 @@ generic-y += syscalls.h generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/mips/include/asm/Kbuild +1 -0
@@ -21,3 +21,4 @@ generic-y += user.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/mn10300/include/asm/Kbuild +1 -0
@@ -11,3 +11,4 @@ generic-y += sections.h generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/nios2/include/asm/Kbuild +1 -0
@@ -64,3 +64,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/openrisc/include/asm/Kbuild +1 -0
@@ -72,3 +72,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/parisc/include/asm/Kbuild +1 -0
@@ -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
@@ -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
@@ -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
@@ -9,3 +9,4 @@ generic-y += preempt.h generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/score/include/asm/Kbuild +1 -0
@@ -15,3 +15,4 @@ generic-y += xor.h generic-y += serial.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/sh/include/asm/Kbuild +1 -0
@@ -40,3 +40,4 @@ generic-y += trace_clock.h generic-y += ucontext.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/sparc/include/asm/Kbuild +1 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Luis R. Rodriguez
maintainerPATCH v5 4/14 tables.h: add linker table support
In reply to Luis R. RodriguezA 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -47,3 +47,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/frv/include/asm/Kbuild +1 -0
@@ -10,3 +10,4 @@ generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/h8300/include/asm/Kbuild +1 -0
@@ -77,3 +77,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/hexagon/include/asm/Kbuild +1 -0
@@ -62,3 +62,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/ia64/include/asm/Kbuild +1 -0
@@ -11,3 +11,4 @@ generic-y += vtime.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/m32r/include/asm/Kbuild +1 -0
@@ -13,3 +13,4 @@ generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/m68k/include/asm/Kbuild +1 -0
@@ -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
@@ -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
@@ -13,3 +13,4 @@ generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/mips/include/asm/Kbuild +1 -0
@@ -22,3 +22,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/mn10300/include/asm/Kbuild +1 -0
@@ -12,3 +12,4 @@ generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/nios2/include/asm/Kbuild +1 -0
@@ -65,3 +65,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/openrisc/include/asm/Kbuild +1 -0
@@ -73,3 +73,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/parisc/include/asm/Kbuild +1 -0
@@ -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
@@ -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
@@ -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
@@ -10,3 +10,4 @@ generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/score/include/asm/Kbuild +1 -0
@@ -16,3 +16,4 @@ generic-y += serial.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/sh/include/asm/Kbuild +1 -0
@@ -41,3 +41,4 @@ generic-y += ucontext.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/sparc/include/asm/Kbuild +1 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
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 standardlinktable_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,);
+ */
+#defineLINKTABLE_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
Luis R. Rodriguez
maintainerRe: [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,);
+ */
+#defineLINKTABLE_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
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()macrohpa 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
23317Signature · 7 lines
With Best Regards, Andy Shevchenko _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Luis R. Rodriguez
maintainerRe: [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()macrohpa 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
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()macrohpa 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()andLINKTABLE_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
Luis R. Rodriguez
maintainerRe: [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()macrohpa 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()andLINKTABLE_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
Luis R. Rodriguez
maintainerPATCH v5 5/14 kbuild: enable option to force compile force-obj-y and force-lib-y
In reply to Luis R. RodriguezLinux 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Luis R. Rodriguez
maintainerPATCH v5 6/14 firmware/Makefile: force recompilation if makefile changes
In reply to Luis R. RodriguezIf you modify the target asm we currently do not force the recompilation of the firmware files. The target asm is in the firmware/Makefile, peg this file as a dependency to require re-compilation of firmware targets when the asm changes.
v3: introduced in this series
--- firmware/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
firmware/Makefile +2 -1
@@ -176,7 +176,8 @@ quiet_cmd_fwbin = MK_FW $@ wordsize_deps := $(wildcard include/config/64bit.h include/config/32bit.h \ include/config/ppc32.h include/config/ppc64.h \ include/config/superh32.h include/config/superh64.h \ - include/config/x86_32.h include/config/x86_64.h) + include/config/x86_32.h include/config/x86_64.h \ + firmware/Makefile) $(patsubst %,$(obj)/%.gen.S, $(fw-shipped-y)): %: $(wordsize_deps) $(call cmd,fwbin,$(patsubst %.gen.S,%,$@))
Signature · 1 line
2.10.1
Luis R. Rodriguez
maintainerPATCH v5 7/14 firmware: port built-in section to linker table
In reply to Luis R. RodriguezThis 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
--- arch/x86/kernel/cpu/microcode/core.c | 8 ++++---- drivers/base/firmware_class.c | 12 ++++++------ firmware/Makefile | 3 ++- include/asm-generic/vmlinux.lds.h | 7 ------- 4 files changed, 12 insertions(+), 18 deletions(-)
arch/x86/kernel/cpu/microcode/core.c +4 -4
@@ -31,6 +31,7 @@#include <linux/cpu.h> #include <linux/fs.h> #include <linux/mm.h> +#include <linux/tables.h> #include <asm/microcode_intel.h> #include <asm/cpu_device_id.h>
@@ -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
@@ -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
@@ -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
@@ -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
Luis R. Rodriguez
maintainerPATCH v5 8/14 jump_label: move guard #endif down where it belongs
In reply to Luis R. RodriguezThe 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
@@ -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
Luis R. Rodriguez
maintainerPATCH v5 9/14 jump_label: port __jump_table to linker tables
In reply to Luis R. RodriguezMove 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Re: [PATCH v5 09/14] jump_label: port __jump_table to linker tables
Quoted 23 lines · Luis R. Rodriguez
Move the
__jump_tablefrom the a custom section solution to a generic solution, this avoiding extravmlinux.lds.hcustomizations.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 boolarch_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
Luis R. Rodriguez
maintainerRe: [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_tablefrom the a custom section solution to a generic solution, this avoiding extravmlinux.lds.hcustomizations.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 boolarch_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"
#definepop_section_tbl_anypop_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
Luis R. Rodriguez
maintainerPATCH v5 10/14 dynamic_debug: port to use linker tables
In reply to Luis R. RodriguezThis 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
--- 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
@@ -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
@@ -4,6 +4,7 @@#if defined(CC_HAVE_ASM_GOTO ) && defined(CONFIG_JUMP_LABEL )#include <linux/jump_label.h> #endif +#include <linux/tables.h> /* * An instance of this structure is created in a special
@@ -50,6 +51,7 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n, const char *modname);#if defined(CONFIG_DYNAMIC_DEBUG ) +DECLARE_LINKTABLE(struct _ddebug, __verbose);extern int ddebug_remove_module (const char *mod_name); extern __printf(2, 3) void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...);
@@ -71,8 +73,7 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor, const char *fmt, ...);#define DEFINE_DYNAMIC_DEBUG_METADATA_KEY (name, fmt, key, init) \ - static struct _ddebug __aligned(8) \ - __attribute__((section("__verbose"))) name = { \ + static LINKTABLE(__verbose, SECTION_ORDER_ANY) name = { \ .modname = KBUILD_MODNAME, \ .function = __func__, \ .filename = __FILE__, \
lib/dynamic_debug.c +6 -7
@@ -37,8 +37,7 @@#include <linux/device.h> #include <linux/netdevice.h> -extern struct _ddebug __start___verbose[]; -extern struct _ddebug __stop___verbose[]; +DEFINE_LINKTABLE(struct _ddebug, __verbose);struct ddebug_table {struct list_head link;
@@ -978,14 +977,14 @@ static int __init dynamic_debug_init(void)int n =0 , entries =0 , modct =0 ;int verbose_bytes =0 ; -if (__start___verbose = __stop___verbose) { -pr_warn ("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n" ); +if (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
@@ -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
Luis R. Rodriguez
maintainerPATCH v5 11/14 kprobes: move kprobe declarations to asm-generic/kprobes.h
In reply to Luis R. RodriguezOften 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
@@ -13,3 +13,4 @@ generic-y += trace_clock.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/arc/include/asm/kprobes.h +4 -2
@@ -9,6 +9,8 @@#ifndef _ARC_KPROBES_H#define _ARC_KPROBES_H +#include <asm-generic/kprobes.h> +#ifdef CONFIG_KPROBES typedef u16 kprobe_opcode_t ;
@@ -55,6 +57,6 @@ void trap_is_kprobe(unsigned long address, struct pt_regs *regs);static void trap_is_kprobe (unsigned long address,struct pt_regs *regs) { } -#endif +#endif /* CONFIG_KPROBES */ -#endif +#endif /* _ARC_KPROBES_H */
arch/arm/include/asm/kprobes.h +4 -0
@@ -16,6 +16,9 @@#ifndef _ARM_KPROBES_H#define _ARM_KPROBES_H +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/types.h> #include <linux/ptrace.h> #include <linux/notifier.h>
@@ -83,4 +86,5 @@ struct arch_optimized_insn {*/ }; +#endif /* CONFIG_KPROBES */ #endif /* _ARM_KPROBES_H */
arch/arm/probes/decode.h +1 -0
@@ -22,6 +22,7 @@#include <linux/types.h> #include <linux/stddef.h> #include <asm/probes.h> +#include <asm/kprobes.h> void __init arm_probes_decode_init (void );
arch/arm64/include/asm/kprobes.h +4 -0
@@ -16,6 +16,9 @@#ifndef _ARM_KPROBES_H#define _ARM_KPROBES_H +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/types.h> #include <linux/ptrace.h> #include <linux/percpu.h>
@@ -57,4 +60,5 @@ int kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr);void kretprobe_trampoline (void );void __kprobes *trampoline_probe_handler (struct pt_regs *regs); +#endif /* CONFIG_KPROBES */ #endif /* _ARM_KPROBES_H */
arch/arm64/kernel/insn.c +1 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -64,3 +64,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += kprobes.h
arch/cris/include/asm/Kbuild +1 -0
@@ -48,3 +48,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/frv/include/asm/Kbuild +1 -0
@@ -11,3 +11,4 @@ generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/h8300/include/asm/Kbuild +1 -0
@@ -78,3 +78,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/hexagon/include/asm/Kbuild +1 -0
@@ -63,3 +63,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/ia64/include/asm/kprobes.h +9 -3
@@ -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
@@ -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
@@ -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
@@ -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
@@ -14,3 +14,4 @@ generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/mips/include/asm/kprobes.h +5 -1
@@ -22,6 +22,9 @@#ifndef _ASM_KPROBES_H#define _ASM_KPROBES_H +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/ptrace.h> #include <linux/types.h>
@@ -94,4 +97,5 @@ struct kprobe_ctlblk {extern int kprobe_exceptions_notify (struct notifier_block *self,unsigned long val,void *data); -#endif /* _ASM_KPROBES_H */ +#endif /* CONFIG_KPROBES */ +#endif /* _ASM_KPROBES_H */
arch/mn10300/include/asm/kprobes.h +6 -1
@@ -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
@@ -66,3 +66,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/openrisc/include/asm/Kbuild +1 -0
@@ -74,3 +74,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/parisc/include/asm/Kbuild +1 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Luis R. Rodriguez
maintainerPATCH v5 12/14 kprobes: port .kprobes.text to section range
In reply to Luis R. Rodriguezkprobe 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.oarch/avr32/kernel/built-in.o: In function `debug_exit_work':
(.text.rng.kprobes.any+0xa8): relocation truncated to fit:R_AVR32_16N_PCREL against `.ex.text'+3aa
make: *** [Makefile:953: vmlinux] Error 1
o open-code section use on scripts/ code -- folks to prefer the simplicity over dealing with having more tool code access kernel headers.
o NOPE: include #include <asm-generic/ranges.h> on compiler.h -- solves a few 0-day compilation issues
v3:
o after v2 arch/arm/kernel/vmlinux-xip.lds.S got kprobe support, this just removes the custom linker script reference to kprobes as that is no longer needed with linker tables.
o split kprobe linker table and kprobe section ranges use into two separate patches. This should make it easier to review and also demos both distinct use types, one a linker table another a simple section range.
v2: introduced this patch in this series
--- arch/arc/kernel/vmlinux.lds.S | 1 - arch/arm/kernel/entry-armv.S | 3 ++- arch/arm/kernel/vmlinux-xip.lds.S | 1 - arch/arm/kernel/vmlinux.lds.S | 1 - arch/arm64/kernel/armv8_deprecated.c | 1 + arch/arm64/kernel/probes/kprobes.c | 4 ++-- arch/arm64/kernel/vmlinux.lds.S | 1 - arch/avr32/kernel/entry-avr32b.S | 13 +++++++++++-- arch/avr32/kernel/vmlinux.lds.S | 1 - arch/blackfin/kernel/vmlinux.lds.S | 1 - arch/c6x/kernel/vmlinux.lds.S | 1 - arch/hexagon/kernel/vmlinux.lds.S | 1 - arch/ia64/kernel/jprobes.S | 3 ++- arch/ia64/kernel/vmlinux.lds.S | 1 - arch/ia64/lib/flush.S | 6 +++--- arch/metag/kernel/vmlinux.lds.S | 1 - arch/microblaze/kernel/vmlinux.lds.S | 1 - arch/mips/kernel/vmlinux.lds.S | 1 - arch/mn10300/kernel/vmlinux.lds.S | 1 - arch/nios2/kernel/vmlinux.lds.S | 1 - arch/openrisc/kernel/vmlinux.lds.S | 1 - arch/parisc/kernel/vmlinux.lds.S | 1 - arch/powerpc/include/asm/ppc_asm.h | 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
@@ -91,7 +91,6 @@ SECTIONS SCHED_TEXT CPUIDLE_TEXT LOCK_TEXT - KPROBES_TEXT *(.fixup) *(.gnu.warning) }
arch/arm/kernel/entry-armv.S +2 -1
@@ -34,6 +34,7 @@ #include "entry-header.S" #include <asm/entry-macro-multi.S> #include <asm/probes.h> +#include <asm/ranges.h> /* * Interrupt handling.
@@ -83,7 +84,7 @@ .endm #ifdef CONFIG_KPROBES - .section .kprobes.text,"ax",%progbits + set_section_rng_type(.text, kprobes, ax, %progbits) #else .text #endif
arch/arm/kernel/vmlinux-xip.lds.S +0 -1
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -74,7 +74,6 @@ SECTIONS LOCK_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT - KPROBES_TEXT *(.fixup) *(.gnu.warning) }
arch/hexagon/kernel/vmlinux.lds.S +0 -1
@@ -52,7 +52,6 @@ SECTIONS SCHED_TEXT CPUIDLE_TEXT LOCK_TEXT - KPROBES_TEXT *(.fixup) } _etext = .;
arch/ia64/kernel/jprobes.S +2 -1
@@ -46,11 +46,12 @@ */ #include <asm/asmmacro.h> #include <asm/break.h> +#include <asm/ranges.h> /* * void jprobe_break(void) */ - .section .kprobes.text, "ax" + set_section_rng(.text, kprobes, ax) ENTRY(jprobe_break) break.m __IA64_BREAK_JPROBE END(jprobe_break)
arch/ia64/kernel/vmlinux.lds.S +0 -1
@@ -48,7 +48,6 @@ SECTIONS { SCHED_TEXT CPUIDLE_TEXT LOCK_TEXT - KPROBES_TEXT *(.gnu.linkonce.t*) }
arch/ia64/lib/flush.S +3 -3
@@ -9,7 +9,7 @@ #include <asm/asmmacro.h> #include <asm/export.h> - +#include <asm/ranges.h> /* * flush_icache_range(start,end)
@@ -21,7 +21,7 @@ * * Note: "in0" and "in1" are preserved for debugging purposes. */ - .section .kprobes.text,"ax" + set_section_rng(.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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -41,7 +41,6 @@ SECTIONS LOCK_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT - KPROBES_TEXT } =0 _etext = .;
arch/openrisc/kernel/vmlinux.lds.S +0 -1
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -43,6 +43,9 @@#include <asm/kprobes.h> #ifdef CONFIG_KPROBES +#include <linux/ranges.h> + +DECLARE_SECTION_RANGE (kprobes);/* kprobe_status settings */ #define KPROBE_HIT_ACTIVE 0x00000001
kernel/kprobes.c +4 -2
@@ -1328,8 +1328,7 @@ 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
@@ -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
@@ -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
@@ -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
Luis R. Rodriguez
maintainerPATCH v5 13/14 kprobes: port blacklist kprobes to linker table
In reply to Luis R. Rodriguezkprobe 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
@@ -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
@@ -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
@@ -3,14 +3,14 @@#if defined(__KERNEL__) && !defined(__ASSEMBLY__)#ifdef CONFIG_KPROBES +#include <linux/tables.h> #include <asm/ranges.h> /* * Blacklist ganerating macro. Specify functions which is not probed * by using this macro. */ # define __NOKPROBE_SYMBOL (fname) \ -static unsigned long __used \ - __attribute__((__section__("_kprobe_blacklist"))) \ +static LINKTABLE_INIT_DATA(_kprobe_blacklist, all) \ _kbl_addr_##fname = (unsigned long)fname;# define NOKPROBE_SYMBOL (fname) __NOKPROBE_SYMBOL(fname)/* Use this to forbid a kprobes attach on very low level functions */
include/asm-generic/vmlinux.lds.h +0 -10
@@ -114,15 +114,6 @@#define BRANCH_PROFILE ()#endif -#ifdef CONFIG_KPROBES -#define KPROBE_BLACKLIST () . = ALIGN(8); \ - VMLINUX_SYMBOL(__start_kprobe_blacklist) = .; \ - 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
@@ -44,8 +44,10 @@#ifdef CONFIG_KPROBES #include <linux/ranges.h> +#include <linux/tables.h> DECLARE_SECTION_RANGE (kprobes); +DECLARE_LINKTABLE(unsigned long, _kprobe_blacklist);/* kprobe_status settings */ #define KPROBE_HIT_ACTIVE 0x00000001
kernel/kprobes.c +4 -7
@@ -2053,14 +2053,13 @@ NOKPROBE_SYMBOL(dump_kprobe);* since a kprobe need not necessarily be at the beginning * of a function. */ -static int __init populate_kprobe_blacklist (unsigned long *start, -unsigned long *end) +static int __init populate_kprobe_blacklist (void ) {unsigned long *iter;struct kprobe_blacklist_entry *ent;unsigned long entry, offset =0 , size =0 ; -for (iter = start; iter < end; iter++) { + LINKTABLE_FOR_EACH(iter, _kprobe_blacklist) { entry =arch_deref_entry_point ((void *)*iter); if (!kernel_text_address(entry) ||
@@ -2125,8 +2124,7 @@ static struct notifier_block kprobe_module_nb = { };/* Markers of _kprobe_blacklist section */ -extern unsigned long __start_kprobe_blacklist[]; -extern unsigned long __stop_kprobe_blacklist[]; +DEFINE_LINKTABLE_INIT_DATA(unsigned long, _kprobe_blacklist);/* Actual kprobes section range */ DEFINE_SECTION_RANGE(kprobes, .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
Luis R. Rodriguez
maintainerPATCH v5 14/14 lib: add linker tables test driver
In reply to Luis R. RodriguezAdd 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Luis R. Rodriguez
maintainerv6 cover linux: generalize sections, ranges and linker tables
In reply to Luis R. RodriguezThis 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
Luis R. Rodriguez
maintainerPATCH 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -62,3 +62,4 @@ generic-y += user.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/cris/include/asm/Kbuild +1 -0
@@ -45,3 +45,4 @@ generic-y += types.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/frv/include/asm/Kbuild +1 -0
@@ -8,3 +8,4 @@ generic-y += mm-arch-hooks.h generic-y += preempt.h generic-y += trace_clock.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/h8300/include/asm/Kbuild +1 -0
@@ -75,3 +75,4 @@ generic-y += unaligned.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/hexagon/include/asm/Kbuild +1 -0
@@ -60,3 +60,4 @@ generic-y += unaligned.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/ia64/include/asm/Kbuild +1 -0
@@ -9,3 +9,4 @@ generic-y += preempt.h generic-y += trace_clock.h generic-y += vtime.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/m32r/include/asm/Kbuild +1 -0
@@ -11,3 +11,4 @@ generic-y += preempt.h generic-y += sections.h generic-y += trace_clock.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/m68k/include/asm/Kbuild +1 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -10,3 +10,4 @@ generic-y += preempt.h generic-y += sections.h generic-y += trace_clock.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/nios2/include/asm/Kbuild +1 -0
@@ -63,3 +63,4 @@ generic-y += user.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/openrisc/include/asm/Kbuild +1 -0
@@ -71,3 +71,4 @@ generic-y += user.h generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h +generic-y += section-core.h
arch/parisc/include/asm/Kbuild +1 -0
@@ -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
@@ -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
@@ -8,3 +8,4 @@ generic-y += mm-arch-hooks.h generic-y += preempt.h generic-y += trace_clock.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/score/include/asm/Kbuild +1 -0
@@ -14,3 +14,4 @@ generic-y += trace_clock.h generic-y += xor.h generic-y += serial.h generic-y += word-at-a-time.h +generic-y += section-core.h
arch/sh/include/asm/Kbuild +1 -0
@@ -39,3 +39,4 @@ generic-y += termios.h generic-y += trace_clock.h generic-y += ucontext.h generic-y += xor.h +generic-y += section-core.h
arch/sparc/include/asm/Kbuild +1 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Borislav Petkov
maintainerRe: [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.hthis adds asections-core.hsince 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_RODATAandmark_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 aCONFIG_HAVE_UNDERSCORE_SYMBOL_PREFIX=yarchitecture. 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.rstDocumentation/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_sectionsDocumentation/sections/conf.py new file +4
-0@@ -0,0 +1,4 @@ +# -*- coding: utf-8; mode: python -*- + +project = 'Linux Kernel ELF sections' +html_search_language = 'en'Documentation/sections/index.rst new file +0
-0
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
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@@ -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.harch/xtensa/include/asm/Kbuild +1
-0@@ -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.hinclude/asm-generic/section-core.h new file +0
-0
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
+ *
+ * .._gabi4ch4: 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 tomark_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@@ -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@@ -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
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 callsmark_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
+ */
voidmark_rodata_ro(void);
#endifinclude/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
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.Luis R. Rodriguez
maintainerPATCH v6 2/14 xtensa: skip adding literal when SORT() is used
In reply to Luis R. RodriguezWhen 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
@@ -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
Luis R. Rodriguez
maintainerPATCH v6 3/14 ranges.h: add helpers to build and identify Linux section ranges
In reply to Luis R. RodriguezSection 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -63,3 +63,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/cris/include/asm/Kbuild +1 -0
@@ -46,3 +46,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/frv/include/asm/Kbuild +1 -0
@@ -9,3 +9,4 @@ generic-y += preempt.h generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/h8300/include/asm/Kbuild +1 -0
@@ -76,3 +76,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/hexagon/include/asm/Kbuild +1 -0
@@ -61,3 +61,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/ia64/include/asm/Kbuild +1 -0
@@ -10,3 +10,4 @@ generic-y += trace_clock.h generic-y += vtime.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/m32r/include/asm/Kbuild +1 -0
@@ -12,3 +12,4 @@ generic-y += sections.h generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/m68k/include/asm/Kbuild +1 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -11,3 +11,4 @@ generic-y += sections.h generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/nios2/include/asm/Kbuild +1 -0
@@ -64,3 +64,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/openrisc/include/asm/Kbuild +1 -0
@@ -72,3 +72,4 @@ generic-y += vga.h generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/parisc/include/asm/Kbuild +1 -0
@@ -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
@@ -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
@@ -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
@@ -9,3 +9,4 @@ generic-y += preempt.h generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/score/include/asm/Kbuild +1 -0
@@ -15,3 +15,4 @@ generic-y += xor.h generic-y += serial.h generic-y += word-at-a-time.h generic-y += section-core.h +generic-y += ranges.h
arch/sh/include/asm/Kbuild +1 -0
@@ -40,3 +40,4 @@ generic-y += trace_clock.h generic-y += ucontext.h generic-y += xor.h generic-y += section-core.h +generic-y += ranges.h
arch/sparc/include/asm/Kbuild +1 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Luis R. Rodriguez
maintainerPATCH v6 4/14 tables.h: add linker table support
In reply to Luis R. RodriguezA 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -47,3 +47,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/frv/include/asm/Kbuild +1 -0
@@ -10,3 +10,4 @@ generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/h8300/include/asm/Kbuild +1 -0
@@ -77,3 +77,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/hexagon/include/asm/Kbuild +1 -0
@@ -62,3 +62,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/ia64/include/asm/Kbuild +1 -0
@@ -11,3 +11,4 @@ generic-y += vtime.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/m32r/include/asm/Kbuild +1 -0
@@ -13,3 +13,4 @@ generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/m68k/include/asm/Kbuild +1 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -12,3 +12,4 @@ generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/nios2/include/asm/Kbuild +1 -0
@@ -65,3 +65,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/openrisc/include/asm/Kbuild +1 -0
@@ -73,3 +73,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/parisc/include/asm/Kbuild +1 -0
@@ -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
@@ -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
@@ -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
@@ -10,3 +10,4 @@ generic-y += trace_clock.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/score/include/asm/Kbuild +1 -0
@@ -16,3 +16,4 @@ generic-y += serial.h generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/sh/include/asm/Kbuild +1 -0
@@ -41,3 +41,4 @@ generic-y += ucontext.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += tables.h
arch/sparc/include/asm/Kbuild +1 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Luis R. Rodriguez
maintainerPATCH v6 5/14 kbuild: enable option to force compile force-obj-y and force-lib-y
In reply to Luis R. RodriguezLinux 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Luis R. Rodriguez
maintainerPATCH v6 6/14 firmware/Makefile: force recompilation if makefile changes
In reply to Luis R. RodriguezIf you modify the target asm we currently do not force the recompilation of the firmware files. The target asm is in the firmware/Makefile, peg this file as a dependency to require re-compilation of firmware targets when the asm changes.
v3: introduced in this series
--- firmware/Makefile | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-)
firmware/Makefile +2 -1
@@ -176,7 +176,8 @@ quiet_cmd_fwbin = MK_FW $@ wordsize_deps := $(wildcard include/config/64bit.h include/config/32bit.h \ include/config/ppc32.h include/config/ppc64.h \ include/config/superh32.h include/config/superh64.h \ - include/config/x86_32.h include/config/x86_64.h) + include/config/x86_32.h include/config/x86_64.h \ + firmware/Makefile) $(patsubst %,$(obj)/%.gen.S, $(fw-shipped-y)): %: $(wordsize_deps) $(call cmd,fwbin,$(patsubst %.gen.S,%,$@))
Signature · 7 lines
2.11.0 _______________________________________________ Xen-devel mailing list [email protected] https://lists.xen.org/xen-devel
Luis R. Rodriguez
maintainerPATCH v6 7/14 firmware: port built-in section to linker table
In reply to Luis R. RodriguezThis 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
--- arch/x86/kernel/cpu/microcode/core.c | 8 ++++---- drivers/base/firmware_class.c | 12 ++++++------ firmware/Makefile | 3 ++- include/asm-generic/vmlinux.lds.h | 7 ------- 4 files changed, 12 insertions(+), 18 deletions(-)
arch/x86/kernel/cpu/microcode/core.c +4 -4
@@ -31,6 +31,7 @@#include <linux/cpu.h> #include <linux/fs.h> #include <linux/mm.h> +#include <linux/tables.h> #include <asm/microcode_intel.h> #include <asm/cpu_device_id.h>
@@ -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
@@ -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
@@ -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
@@ -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
Luis R. Rodriguez
maintainerPATCH v6 8/14 jump_label: move guard #endif down where it belongs
In reply to Luis R. RodriguezThe 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
@@ -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
Luis R. Rodriguez
maintainerPATCH v6 9/14 jump_label: port __jump_table to linker tables
In reply to Luis R. RodriguezMove 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Luis R. Rodriguez
maintainerPATCH v6 10/14 dynamic_debug: port to use linker tables
In reply to Luis R. RodriguezThis 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
--- 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
@@ -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
@@ -4,6 +4,7 @@#if defined(CC_HAVE_ASM_GOTO ) && defined(CONFIG_JUMP_LABEL )#include <linux/jump_label.h> #endif +#include <linux/tables.h> /* * An instance of this structure is created in a special
@@ -50,6 +51,7 @@ int ddebug_add_module(struct _ddebug *tab, unsigned int n, const char *modname);#if defined(CONFIG_DYNAMIC_DEBUG ) +DECLARE_LINKTABLE(struct _ddebug, __verbose);extern int ddebug_remove_module (const char *mod_name); extern __printf(2, 3) void __dynamic_pr_debug(struct _ddebug *descriptor, const char *fmt, ...);
@@ -71,8 +73,7 @@ void __dynamic_netdev_dbg(struct _ddebug *descriptor, const char *fmt, ...);#define DEFINE_DYNAMIC_DEBUG_METADATA_KEY (name, fmt, key, init) \ - static struct _ddebug __aligned(8) \ - __attribute__((section("__verbose"))) name = { \ + static LINKTABLE(__verbose, SECTION_ORDER_ANY) name = { \ .modname = KBUILD_MODNAME, \ .function = __func__, \ .filename = __FILE__, \
lib/dynamic_debug.c +6 -7
@@ -37,8 +37,7 @@#include <linux/device.h> #include <linux/netdevice.h> -extern struct _ddebug __start___verbose[]; -extern struct _ddebug __stop___verbose[]; +DEFINE_LINKTABLE(struct _ddebug, __verbose);struct ddebug_table {struct list_head link;
@@ -978,14 +977,14 @@ static int __init dynamic_debug_init(void)int n =0 , entries =0 , modct =0 ;int verbose_bytes =0 ; -if (__start___verbose == __stop___verbose) { -pr_warn ("_ddebug table is empty in a CONFIG_DYNAMIC_DEBUG build\n" ); +if (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
@@ -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
Luis R. Rodriguez
maintainerPATCH v6 11/14 kprobes: move kprobe declarations to asm-generic/kprobes.h
In reply to Luis R. RodriguezOften 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
@@ -13,3 +13,4 @@ generic-y += trace_clock.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/arc/include/asm/kprobes.h +4 -2
@@ -9,6 +9,8 @@#ifndef _ARC_KPROBES_H#define _ARC_KPROBES_H +#include <asm-generic/kprobes.h> +#ifdef CONFIG_KPROBES typedef u16 kprobe_opcode_t ;
@@ -55,6 +57,6 @@ void trap_is_kprobe(unsigned long address, struct pt_regs *regs);static void trap_is_kprobe (unsigned long address,struct pt_regs *regs) { } -#endif +#endif /* CONFIG_KPROBES */ -#endif +#endif /* _ARC_KPROBES_H */
arch/arm/include/asm/kprobes.h +4 -0
@@ -16,6 +16,9 @@#ifndef _ARM_KPROBES_H#define _ARM_KPROBES_H +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/types.h> #include <linux/ptrace.h> #include <linux/notifier.h>
@@ -83,4 +86,5 @@ struct arch_optimized_insn {*/ }; +#endif /* CONFIG_KPROBES */ #endif /* _ARM_KPROBES_H */
arch/arm/probes/decode.h +1 -0
@@ -22,6 +22,7 @@#include <linux/types.h> #include <linux/stddef.h> #include <asm/probes.h> +#include <asm/kprobes.h> void __init arm_probes_decode_init (void );
arch/arm64/include/asm/kprobes.h +4 -0
@@ -16,6 +16,9 @@#ifndef _ARM_KPROBES_H#define _ARM_KPROBES_H +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/types.h> #include <linux/ptrace.h> #include <linux/percpu.h>
@@ -57,4 +60,5 @@ int kprobe_single_step_handler(struct pt_regs *regs, unsigned int esr);void kretprobe_trampoline (void );void __kprobes *trampoline_probe_handler (struct pt_regs *regs); +#endif /* CONFIG_KPROBES */ #endif /* _ARM_KPROBES_H */
arch/arm64/kernel/insn.c +1 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -64,3 +64,4 @@ generic-y += word-at-a-time.h generic-y += xor.h generic-y += section-core.h generic-y += ranges.h +generic-y += kprobes.h
arch/cris/include/asm/Kbuild +1 -0
@@ -48,3 +48,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/frv/include/asm/Kbuild +1 -0
@@ -11,3 +11,4 @@ generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/h8300/include/asm/Kbuild +1 -0
@@ -78,3 +78,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/hexagon/include/asm/Kbuild +1 -0
@@ -63,3 +63,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/ia64/include/asm/kprobes.h +9 -3
@@ -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
@@ -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
@@ -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
@@ -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
@@ -14,3 +14,4 @@ generic-y += word-at-a-time.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/mips/include/asm/kprobes.h +5 -1
@@ -22,6 +22,9 @@#ifndef _ASM_KPROBES_H#define _ASM_KPROBES_H +#include <asm-generic/kprobes.h> + +#ifdef CONFIG_KPROBES #include <linux/ptrace.h> #include <linux/types.h>
@@ -94,4 +97,5 @@ struct kprobe_ctlblk {extern int kprobe_exceptions_notify (struct notifier_block *self,unsigned long val,void *data); -#endif /* _ASM_KPROBES_H */ +#endif /* CONFIG_KPROBES */ +#endif /* _ASM_KPROBES_H */
arch/mn10300/include/asm/kprobes.h +6 -1
@@ -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
@@ -66,3 +66,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/openrisc/include/asm/Kbuild +1 -0
@@ -74,3 +74,4 @@ generic-y += xor.h generic-y += section-core.h generic-y += ranges.h generic-y += tables.h +generic-y += kprobes.h
arch/parisc/include/asm/Kbuild +1 -0
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
Luis R. Rodriguez
maintainerPATCH v6 12/14 kprobes: port .kprobes.text to section range
In reply to Luis R. Rodriguezkprobe 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.oarch/avr32/kernel/built-in.o: In function `debug_exit_work':
(.text.rng.kprobes.any+0xa8): relocation truncated to fit:R_AVR32_16N_PCREL against `.ex.text'+3aa
make: *** [Makefile:953: vmlinux] Error 1
o open-code section use on scripts/ code -- folks to prefer the simplicity over dealing with having more tool code access kernel headers.
o NOPE: include #include <asm-generic/ranges.h> on compiler.h -- solves a few 0-day compilation issues
v3:
o after v2 arch/arm/kernel/vmlinux-xip.lds.S got kprobe support, this just removes the custom linker script reference to kprobes as that is no longer needed with linker tables.
o split kprobe linker table and kprobe section ranges use into two separate patches. This should make it easier to review and also demos both distinct use types, one a linker table another a simple section range.
v2: introduced this patch in this series
--- arch/arc/kernel/vmlinux.lds.S | 1 - arch/arm/kernel/entry-armv.S | 3 ++- arch/arm/kernel/vmlinux-xip.lds.S | 1 - arch/arm/kernel/vmlinux.lds.S | 1 - arch/arm64/kernel/armv8_deprecated.c | 1 + arch/arm64/kernel/probes/kprobes.c | 4 ++-- arch/arm64/kernel/vmlinux.lds.S | 1 - arch/avr32/kernel/entry-avr32b.S | 13 +++++++++++-- arch/avr32/kernel/vmlinux.lds.S | 1 - arch/blackfin/kernel/vmlinux.lds.S | 1 - arch/c6x/kernel/vmlinux.lds.S | 1 - arch/hexagon/kernel/vmlinux.lds.S | 1 - arch/ia64/kernel/jprobes.S | 3 ++- arch/ia64/kernel/vmlinux.lds.S | 1 - arch/ia64/lib/flush.S | 6 +++--- arch/metag/kernel/vmlinux.lds.S | 1 - arch/microblaze/kernel/vmlinux.lds.S | 1 - arch/mips/kernel/vmlinux.lds.S | 1 - arch/mn10300/kernel/vmlinux.lds.S | 1 - arch/nios2/kernel/vmlinux.lds.S | 1 - arch/openrisc/kernel/vmlinux.lds.S | 1 - arch/parisc/kernel/vmlinux.lds.S | 1 - arch/powerpc/include/asm/ppc_asm.h | 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
@@ -91,7 +91,6 @@ SECTIONS SCHED_TEXT CPUIDLE_TEXT LOCK_TEXT - KPROBES_TEXT *(.fixup) *(.gnu.warning) }
arch/arm/kernel/entry-armv.S +2 -1
@@ -34,6 +34,7 @@ #include "entry-header.S" #include <asm/entry-macro-multi.S> #include <asm/probes.h> +#include <asm/ranges.h> /* * Interrupt handling.
@@ -83,7 +84,7 @@ .endm #ifdef CONFIG_KPROBES - .section .kprobes.text,"ax",%progbits + set_section_rng_type(.text, kprobes, ax, %progbits) #else .text #endif
arch/arm/kernel/vmlinux-xip.lds.S +0 -1
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -74,7 +74,6 @@ SECTIONS LOCK_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT - KPROBES_TEXT *(.fixup) *(.gnu.warning) }
arch/hexagon/kernel/vmlinux.lds.S +0 -1
@@ -52,7 +52,6 @@ SECTIONS SCHED_TEXT CPUIDLE_TEXT LOCK_TEXT - KPROBES_TEXT *(.fixup) } _etext = .;
arch/ia64/kernel/jprobes.S +2 -1
@@ -46,11 +46,12 @@ */ #include <asm/asmmacro.h> #include <asm/break.h> +#include <asm/ranges.h> /* * void jprobe_break(void) */ - .section .kprobes.text, "ax" + set_section_rng(.text, kprobes, ax) ENTRY(jprobe_break) break.m __IA64_BREAK_JPROBE END(jprobe_break)
arch/ia64/kernel/vmlinux.lds.S +0 -1
@@ -48,7 +48,6 @@ SECTIONS { SCHED_TEXT CPUIDLE_TEXT LOCK_TEXT - KPROBES_TEXT *(.gnu.linkonce.t*) }
arch/ia64/lib/flush.S +3 -3
@@ -9,7 +9,7 @@ #include <asm/asmmacro.h> #include <asm/export.h> - +#include <asm/ranges.h> /* * flush_icache_range(start,end)
@@ -21,7 +21,7 @@ * * Note: "in0" and "in1" are preserved for debugging purposes. */ - .section .kprobes.text,"ax" + set_section_rng(.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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -41,7 +41,6 @@ SECTIONS LOCK_TEXT IRQENTRY_TEXT SOFTIRQENTRY_TEXT - KPROBES_TEXT } =0 _etext = .;
arch/openrisc/kernel/vmlinux.lds.S +0 -1
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -43,6 +43,9 @@#include <asm/kprobes.h> #ifdef CONFIG_KPROBES +#include <linux/ranges.h> + +DECLARE_SECTION_RANGE (kprobes);/* kprobe_status settings */ #define KPROBE_HIT_ACTIVE 0x00000001
kernel/kprobes.c +4 -2
@@ -1328,8 +1328,7 @@ 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
@@ -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
@@ -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
@@ -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
Luis R. Rodriguez
maintainerPATCH v6 13/14 kprobes: port blacklist kprobes to linker table
In reply to Luis R. Rodriguezkprobe 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
@@ -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
@@ -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
@@ -3,14 +3,14 @@#if defined(__KERNEL__) && !defined(__ASSEMBLY__)#ifdef CONFIG_KPROBES +#include <linux/tables.h> #include <asm/ranges.h> /* * Blacklist ganerating macro. Specify functions which is not probed * by using this macro. */ # define __NOKPROBE_SYMBOL (fname) \ -static unsigned long __used \ - __attribute__((__section__("_kprobe_blacklist"))) \ +static LINKTABLE_INIT_DATA(_kprobe_blacklist, all) \ _kbl_addr_##fname = (unsigned long)fname;# define NOKPROBE_SYMBOL (fname) __NOKPROBE_SYMBOL(fname)/* Use this to forbid a kprobes attach on very low level functions */
include/asm-generic/vmlinux.lds.h +0 -10
@@ -114,15 +114,6 @@#define BRANCH_PROFILE ()#endif -#ifdef CONFIG_KPROBES -#define KPROBE_BLACKLIST () . = ALIGN(8); \ - VMLINUX_SYMBOL(__start_kprobe_blacklist) = .; \ - 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
@@ -44,8 +44,10 @@#ifdef CONFIG_KPROBES #include <linux/ranges.h> +#include <linux/tables.h> DECLARE_SECTION_RANGE (kprobes); +DECLARE_LINKTABLE(unsigned long, _kprobe_blacklist);/* kprobe_status settings */ #define KPROBE_HIT_ACTIVE 0x00000001
kernel/kprobes.c +4 -7
@@ -2053,14 +2053,13 @@ NOKPROBE_SYMBOL(dump_kprobe);* since a kprobe need not necessarily be at the beginning * of a function. */ -static int __init populate_kprobe_blacklist (unsigned long *start, -unsigned long *end) +static int __init populate_kprobe_blacklist (void ) {unsigned long *iter;struct kprobe_blacklist_entry *ent;unsigned long entry, offset =0 , size =0 ; -for (iter = start; iter < end; iter++) { +linktable_for_each (iter, _kprobe_blacklist) { entry =arch_deref_entry_point ((void *)*iter); if (!kernel_text_address(entry) ||
@@ -2125,8 +2124,7 @@ static struct notifier_block kprobe_module_nb = { };/* Markers of _kprobe_blacklist section */ -extern unsigned long __start_kprobe_blacklist[]; -extern unsigned long __stop_kprobe_blacklist[]; +DEFINE_LINKTABLE_INIT_DATA(unsigned long, _kprobe_blacklist);/* Actual kprobes section range */ DEFINE_SECTION_RANGE(kprobes, .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
Luis R. Rodriguez
maintainerPATCH v6 14/14 lib: add linker tables test driver
In reply to Luis R. RodriguezAdd 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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
@@ -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
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 thetables.hmacros. 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_22mips_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 whenSORT()is usedranges.h: add helpers to build and identify Linux section rangestables.h: add linker table support
kbuild: enable option to force compile force-obj-y and force-lib-yfirmware/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_tableto linker tables
dynamic_debug: port to use linker tables
kprobes: move kprobe declarations toasm-generic/kprobes.h
kprobes: port .kprobes.text to section range
kprobes: port blacklist kprobes to linker table
lib: add linker tables test driverDocumentation/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.rstcreate mode 100644Documentation/sections/conf.pycreate mode 100644Documentation/sections/index.rstcreate mode 100644Documentation/sections/linker-tables.rstcreate mode 100644Documentation/sections/ranges.rstcreate mode 100644Documentation/sections/section-core.rstcreate mode 100644arch/c6x/include/asm/tables.hcreate mode 100644arch/unicore32/include/asm/section-core.hcreate mode 100644include/asm-generic/kprobes.hcreate mode 100644include/asm-generic/ranges.hcreate mode 100644include/asm-generic/section-core.hcreate mode 100644include/asm-generic/tables.hcreate mode 100644include/linux/ranges.h
create mode 100644include/linux/sections.h
create mode 100644include/linux/tables.h
create mode 100644lib/test_linktables/Makefilecreate mode 100644lib/test_linktables/test-linktables-00.ccreate mode 100644lib/test_linktables/test-linktables-01.ccreate mode 100644lib/test_linktables/test-linktables-02.ccreate mode 100644lib/test_linktables/test-linktables-03.ccreate mode 100644lib/test_linktables/test-linktables-04.ccreate mode 100644lib/test_linktables/test-linktables.ccreate mode 100644lib/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
Luis R. Rodriguez
maintainerQuoted 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:
Reviewed-by Andy Shevchenko <[email protected]>
Great thanks for the review!
Luis
_______________________________________________
Xen-devel mailing list
[email protected]
https://lists.xen.org/xen-devel
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
Luis R. Rodriguez
maintainerQuoted 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
3a0af8fd61f90920f6fa04e4f1e9a6a73c1b4fd2Author: Thomas Graf <[email protected]> Date: Wed Nov 30 17:10:10 2016 +0100bpf: 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
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 +0100bpf: 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
@@ -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
Luis R. Rodriguez
maintainerQuoted 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_PCRELagainst `.text'+2930But 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
Luis R. Rodriguez
maintainerv7 cover linux: generalize sections, ranges and linker tables
In reply to Luis R. RodriguezThis 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.
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