Commit b0b3b2c7 authored by Christophe Leroy's avatar Christophe Leroy Committed by Michael Ellerman

powerpc: Switch to relative jump labels

Convert powerpc to relative jump labels.

Before the patch, pseries_defconfig vmlinux.o has:
9074 __jump_table  0003f2a0  0000000000000000  0000000000000000  01321fa8  2**0

With the patch, the same config gets:
9074 __jump_table  0002a0e0  0000000000000000  0000000000000000  01321fb4  2**0

Size is 258720 without the patch, 172256 with the patch.
That's a 33% size reduction.

Largely copied from commit c296146c ("arm64/kernel: jump_label:
Switch to relative references")
Signed-off-by: default avatarChristophe Leroy <christophe.leroy@csgroup.eu>
Signed-off-by: default avatarMichael Ellerman <mpe@ellerman.id.au>
Link: https://lore.kernel.org/r/828348da7868eda953ce023994404dfc49603b64.1616514473.git.christophe.leroy@csgroup.eu
parent 40272035
...@@ -184,6 +184,7 @@ config PPC ...@@ -184,6 +184,7 @@ config PPC
select HAVE_ARCH_AUDITSYSCALL select HAVE_ARCH_AUDITSYSCALL
select HAVE_ARCH_HUGE_VMAP if PPC_BOOK3S_64 && PPC_RADIX_MMU select HAVE_ARCH_HUGE_VMAP if PPC_BOOK3S_64 && PPC_RADIX_MMU
select HAVE_ARCH_JUMP_LABEL select HAVE_ARCH_JUMP_LABEL
select HAVE_ARCH_JUMP_LABEL_RELATIVE
select HAVE_ARCH_KASAN if PPC32 && PPC_PAGE_SHIFT <= 14 select HAVE_ARCH_KASAN if PPC32 && PPC_PAGE_SHIFT <= 14
select HAVE_ARCH_KASAN_VMALLOC if PPC32 && PPC_PAGE_SHIFT <= 14 select HAVE_ARCH_KASAN_VMALLOC if PPC32 && PPC_PAGE_SHIFT <= 14
select HAVE_ARCH_KGDB select HAVE_ARCH_KGDB
......
...@@ -20,7 +20,8 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran ...@@ -20,7 +20,8 @@ static __always_inline bool arch_static_branch(struct static_key *key, bool bran
asm_volatile_goto("1:\n\t" asm_volatile_goto("1:\n\t"
"nop # arch_static_branch\n\t" "nop # arch_static_branch\n\t"
".pushsection __jump_table, \"aw\"\n\t" ".pushsection __jump_table, \"aw\"\n\t"
JUMP_ENTRY_TYPE "1b, %l[l_yes], %c0\n\t" ".long 1b - ., %l[l_yes] - .\n\t"
JUMP_ENTRY_TYPE "%c0 - .\n\t"
".popsection \n\t" ".popsection \n\t"
: : "i" (&((char *)key)[branch]) : : l_yes); : : "i" (&((char *)key)[branch]) : : l_yes);
...@@ -34,7 +35,8 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool ...@@ -34,7 +35,8 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool
asm_volatile_goto("1:\n\t" asm_volatile_goto("1:\n\t"
"b %l[l_yes] # arch_static_branch_jump\n\t" "b %l[l_yes] # arch_static_branch_jump\n\t"
".pushsection __jump_table, \"aw\"\n\t" ".pushsection __jump_table, \"aw\"\n\t"
JUMP_ENTRY_TYPE "1b, %l[l_yes], %c0\n\t" ".long 1b - ., %l[l_yes] - .\n\t"
JUMP_ENTRY_TYPE "%c0 - .\n\t"
".popsection \n\t" ".popsection \n\t"
: : "i" (&((char *)key)[branch]) : : l_yes); : : "i" (&((char *)key)[branch]) : : l_yes);
...@@ -43,23 +45,12 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool ...@@ -43,23 +45,12 @@ static __always_inline bool arch_static_branch_jump(struct static_key *key, bool
return true; return true;
} }
#ifdef CONFIG_PPC64
typedef u64 jump_label_t;
#else
typedef u32 jump_label_t;
#endif
struct jump_entry {
jump_label_t code;
jump_label_t target;
jump_label_t key;
};
#else #else
#define ARCH_STATIC_BRANCH(LABEL, KEY) \ #define ARCH_STATIC_BRANCH(LABEL, KEY) \
1098: nop; \ 1098: nop; \
.pushsection __jump_table, "aw"; \ .pushsection __jump_table, "aw"; \
FTR_ENTRY_LONG 1098b, LABEL, KEY; \ .long 1098b - ., LABEL - .; \
FTR_ENTRY_LONG KEY; \
.popsection .popsection
#endif #endif
......
...@@ -11,10 +11,10 @@ ...@@ -11,10 +11,10 @@
void arch_jump_label_transform(struct jump_entry *entry, void arch_jump_label_transform(struct jump_entry *entry,
enum jump_label_type type) enum jump_label_type type)
{ {
struct ppc_inst *addr = (struct ppc_inst *)(unsigned long)entry->code; struct ppc_inst *addr = (struct ppc_inst *)jump_entry_code(entry);
if (type == JUMP_LABEL_JMP) if (type == JUMP_LABEL_JMP)
patch_branch(addr, entry->target, 0); patch_branch(addr, jump_entry_target(entry), 0);
else else
patch_instruction(addr, ppc_inst(PPC_INST_NOP)); patch_instruction(addr, ppc_inst(PPC_INST_NOP));
} }
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment