Move the __jump_table from the a custom section solution
to a generic solution, this avoiding extra vmlinux.lds.h
customizations.
This also demos the use of the .data linker table and of
the shared asm call push_section_tbl().
Built-in kernel functionality was tested with CONFIG_STATIC_KEYS_SELFTEST.
Moduler kernel functionality was tested with CONFIG_TEST_STATIC_KEYS.
Both work as expected.
Since __jump_table sections are also supported per
module this also required expanding module-common.lds.S
to capture and fold all .data.tlb.__jump_table.* onto
the the section __jump_table -- in this case for modules
need to keep a reference in place, given the alternative
is to use DEFINE_LINKTABLE(struct jump_entry, __jump_table)
per module -- and later through macro hacks instantiate
the jump entries per module upon init. This is doable but
we'd loose out on the sorting of the table using the
linker, to sort we'd always still need to expand the
module common linker script. An alternative mechanism
is possible which would make these custom module sections
extensions dynamic without requiring manual changes, this
however is best done later through a separate evolution
once linker tables are in place.
A careful reviewer may note that some architectures use
"\n\t" to separate asm code, while others just use a new line.
Upon review last time it was deemed reasonable to for all
architectures to just use "\n", this is defined as ASM_CMD_SEP,
and if an architecture needs to override they can do so on their
architecture sections.h prior to including asm-generic/sections.h
v5:
o Use ..tbl instead of .tbl as suggested by Nicholas Piggin.
This is the typical way to avoid clash with compiler generated
section.
o Replace section macros with section names
o Use LINKTABLE_START() and LINKTABLE_END()
o fixed tile jump label port -- tile got jump label support as of commit
65a792e84f25d1 ("tile/jump_label: add jump label support for TILE-Gx"),
as such we just needed to adjust the asm to account for the new
linker table API use. This commit was merged as of v4.5-rc1.
v4:
o Some architectures allow linker scripts to follow including header
files, some others do not, so if you need a helper on a linker script
you need to explicitly include it. So for instance although
scripts/module-common.lds.S includes and this file
includes , 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
Signed-off-by: Luis R. Rodriguez
---
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(-)
diff --git a/arch/arm/include/asm/jump_label.h
b/arch/arm/include/asm/jump_label.h
index 34f7b6980d21..609e0592a942 100644
--- a/arch/arm/include/asm/jump_label.h
+++ b/arch/arm/include/asm/jump_label.h
@@ -1,6 +1,8 @@
#ifndef _ASM_ARM_JUMP_LABEL_H
#define _ASM_ARM_JUMP_LABEL_H
+#include
+
#ifndef __ASSEMBLY__
#include
@@ -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"