Skip to content

Commit

Permalink
jump_label, x86: Introduce jump_entry_size()
Browse files Browse the repository at this point in the history
This allows architectures to have variable sized jumps.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Signed-off-by: Ingo Molnar <mingo@kernel.org>
Link: https://lore.kernel.org/r/20210506194157.786777050@infradead.org
  • Loading branch information
Peter Zijlstra authored and Ingo Molnar committed May 12, 2021
1 parent f9510fa commit fa5e5dc
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 3 deletions.
4 changes: 2 additions & 2 deletions arch/x86/include/asm/jump_label.h
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,6 @@

#define HAVE_JUMP_LABEL_BATCH

#define JUMP_LABEL_NOP_SIZE 5

#include <asm/asm.h>
#include <asm/nops.h>

Expand Down Expand Up @@ -47,6 +45,8 @@ static __always_inline bool arch_static_branch_jump(struct static_key * const ke
return true;
}

extern int arch_jump_entry_size(struct jump_entry *entry);

#endif /* __ASSEMBLY__ */

#endif
7 changes: 7 additions & 0 deletions arch/x86/kernel/jump_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,13 @@
#include <asm/alternative.h>
#include <asm/text-patching.h>

#define JUMP_LABEL_NOP_SIZE JMP32_INSN_SIZE

int arch_jump_entry_size(struct jump_entry *entry)
{
return JMP32_INSN_SIZE;
}

static const void *
__jump_label_set_jump_code(struct jump_entry *entry, enum jump_label_type type)
{
Expand Down
9 changes: 9 additions & 0 deletions include/linux/jump_label.h
Original file line number Diff line number Diff line change
Expand Up @@ -176,6 +176,15 @@ static inline void jump_entry_set_init(struct jump_entry *entry)
entry->key |= 2;
}

static inline int jump_entry_size(struct jump_entry *entry)
{
#ifdef JUMP_LABEL_NOP_SIZE
return JUMP_LABEL_NOP_SIZE;
#else
return arch_jump_entry_size(entry);
#endif
}

#endif
#endif

Expand Down
2 changes: 1 addition & 1 deletion kernel/jump_label.c
Original file line number Diff line number Diff line change
Expand Up @@ -309,7 +309,7 @@ EXPORT_SYMBOL_GPL(jump_label_rate_limit);
static int addr_conflict(struct jump_entry *entry, void *start, void *end)
{
if (jump_entry_code(entry) <= (unsigned long)end &&
jump_entry_code(entry) + JUMP_LABEL_NOP_SIZE > (unsigned long)start)
jump_entry_code(entry) + jump_entry_size(entry) > (unsigned long)start)
return 1;

return 0;
Expand Down

0 comments on commit fa5e5dc

Please sign in to comment.