Skip to content

Commit b34006c

Browse files
Ard BiesheuvelKAGA-KOKO
authored andcommitted
x86/jump_table: Use relative references
Similar to the arm64 case, 64-bit x86 can benefit from using relative references rather than absolute ones when emitting struct jump_entry instances. Not only does this reduce the memory footprint of the entries themselves by 33%, it also removes the need for carrying relocation metadata on relocatable builds (i.e., for KASLR) which saves a fair chunk of .init space as well (although the savings are not as dramatic as on arm64) Signed-off-by: Ard Biesheuvel <[email protected]> Signed-off-by: Thomas Gleixner <[email protected]> Acked-by: Peter Zijlstra (Intel) <[email protected]> Cc: [email protected] Cc: [email protected] Cc: Arnd Bergmann <[email protected]> Cc: Heiko Carstens <[email protected]> Cc: Kees Cook <[email protected]> Cc: Will Deacon <[email protected]> Cc: Catalin Marinas <[email protected]> Cc: Steven Rostedt <[email protected]> Cc: Martin Schwidefsky <[email protected]> Cc: Jessica Yu <[email protected]> Link: https://lkml.kernel.org/r/[email protected]
1 parent 9fc0f79 commit b34006c

File tree

3 files changed

+11
-18
lines changed

3 files changed

+11
-18
lines changed

arch/x86/Kconfig

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,7 @@ config X86
119119
select HAVE_ARCH_AUDITSYSCALL
120120
select HAVE_ARCH_HUGE_VMAP if X86_64 || X86_PAE
121121
select HAVE_ARCH_JUMP_LABEL
122+
select HAVE_ARCH_JUMP_LABEL_RELATIVE
122123
select HAVE_ARCH_KASAN if X86_64
123124
select HAVE_ARCH_KGDB
124125
select HAVE_ARCH_MMAP_RND_BITS if MMU

arch/x86/include/asm/jump_label.h

Lines changed: 8 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,8 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran
3737
".byte " __stringify(STATIC_KEY_INIT_NOP) "\n\t"
3838
".pushsection __jump_table, \"aw\" \n\t"
3939
_ASM_ALIGN "\n\t"
40-
_ASM_PTR "1b, %l[l_yes], %c0 + %c1 \n\t"
40+
".long 1b - ., %l[l_yes] - . \n\t"
41+
_ASM_PTR "%c0 + %c1 - .\n\t"
4142
".popsection \n\t"
4243
: : "i" (key), "i" (branch) : : l_yes);
4344

@@ -53,7 +54,8 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool
5354
"2:\n\t"
5455
".pushsection __jump_table, \"aw\" \n\t"
5556
_ASM_ALIGN "\n\t"
56-
_ASM_PTR "1b, %l[l_yes], %c0 + %c1 \n\t"
57+
".long 1b - ., %l[l_yes] - . \n\t"
58+
_ASM_PTR "%c0 + %c1 - .\n\t"
5759
".popsection \n\t"
5860
: : "i" (key), "i" (branch) : : l_yes);
5961

@@ -62,18 +64,6 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool
6264
return true;
6365
}
6466

65-
#ifdef CONFIG_X86_64
66-
typedef u64 jump_label_t;
67-
#else
68-
typedef u32 jump_label_t;
69-
#endif
70-
71-
struct jump_entry {
72-
jump_label_t code;
73-
jump_label_t target;
74-
jump_label_t key;
75-
};
76-
7767
#else /* __ASSEMBLY__ */
7868

7969
.macro STATIC_JUMP_IF_TRUE target, key, def
@@ -88,7 +78,8 @@ struct jump_entry {
8878
.endif
8979
.pushsection __jump_table, "aw"
9080
_ASM_ALIGN
91-
_ASM_PTR .Lstatic_jump_\@, \target, \key
81+
.long .Lstatic_jump_\@ - ., \target - .
82+
_ASM_PTR \key - .
9283
.popsection
9384
.endm
9485

@@ -104,7 +95,8 @@ struct jump_entry {
10495
.endif
10596
.pushsection __jump_table, "aw"
10697
_ASM_ALIGN
107-
_ASM_PTR .Lstatic_jump_\@, \target, \key + 1
98+
.long .Lstatic_jump_\@ - ., \target - .
99+
_ASM_PTR \key + 1 - .
108100
.popsection
109101
.endm
110102

tools/objtool/special.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,9 @@
3030
#define EX_ORIG_OFFSET 0
3131
#define EX_NEW_OFFSET 4
3232

33-
#define JUMP_ENTRY_SIZE 24
33+
#define JUMP_ENTRY_SIZE 16
3434
#define JUMP_ORIG_OFFSET 0
35-
#define JUMP_NEW_OFFSET 8
35+
#define JUMP_NEW_OFFSET 4
3636

3737
#define ALT_ENTRY_SIZE 13
3838
#define ALT_ORIG_OFFSET 0

0 commit comments

Comments
 (0)