[PATCH 03/13] jump_label/x86: Avoid decoding instructions for jump entry size

From: Jiri Olsa

Date: Mon Nov 09 2026 - 14:55:29 EST


Determine the jump entry size from its opcode or NOP encoding instead of
decoding the instruction. This reduces kprobe registration time when
checking jump label entries.

Signed-off-by: Jiri Olsa <jolsa@xxxxxxxxxx>
---
arch/x86/kernel/jump_label.c | 14 +++++++++-----
1 file changed, 9 insertions(+), 5 deletions(-)

diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
index a7949a54a0ff..848a2aee05bd 100644
--- a/arch/x86/kernel/jump_label.c
+++ b/arch/x86/kernel/jump_label.c
@@ -15,16 +15,20 @@
#include <asm/kprobes.h>
#include <asm/alternative.h>
#include <asm/text-patching.h>
-#include <asm/insn.h>

int arch_jump_entry_size(struct jump_entry *entry)
{
- struct insn insn = {};
+ const u8 *code = (void *)jump_entry_code(entry);

- insn_decode_kernel(&insn, (void *)jump_entry_code(entry));
- BUG_ON(insn.length != 2 && insn.length != 5);
+ if (code[0] == JMP8_INSN_OPCODE ||
+ !memcmp(code, x86_nops[JMP8_INSN_SIZE], JMP8_INSN_SIZE))
+ return JMP8_INSN_SIZE;

- return insn.length;
+ if (code[0] == JMP32_INSN_OPCODE ||
+ !memcmp(code, x86_nops[JMP32_INSN_SIZE], JMP32_INSN_SIZE))
+ return JMP32_INSN_SIZE;
+
+ BUG();
}

struct jump_label_patch {
--
2.43.0