jump_label, x86: Introduce jump_entry_size()
authorPeter Zijlstra <peterz@infradead.org>
Thu, 6 May 2021 19:33:58 +0000 (21:33 +0200)
committerIngo Molnar <mingo@kernel.org>
Wed, 12 May 2021 12:54:55 +0000 (14:54 +0200)
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
arch/x86/include/asm/jump_label.h
arch/x86/kernel/jump_label.c
include/linux/jump_label.h
kernel/jump_label.c

index dfdc2b1c17ddd7aa570638b8709b70d9afad2a9d..d85802a00629634bd0c88ec6f0e3bbbfbdca3318 100644 (file)
@@ -4,8 +4,6 @@
 
 #define HAVE_JUMP_LABEL_BATCH
 
-#define JUMP_LABEL_NOP_SIZE 5
-
 #include <asm/asm.h>
 #include <asm/nops.h>
 
@@ -47,6 +45,8 @@ l_yes:
        return true;
 }
 
+extern int arch_jump_entry_size(struct jump_entry *entry);
+
 #endif /* __ASSEMBLY__ */
 
 #endif
index 638d3b9be0ad2b1ee97a6ae563466a3730520cfa..a29eecc14c94db55012a88fc61451b06bf4819df 100644 (file)
 #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)
 {
index 05f5554d860f5cd44e80885a084da7dfd60f93fe..8c45f58292ac4c785b112947e88b4281e2b17834 100644 (file)
@@ -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
 
index ba39fbb1f8e7382c4b0bd7ffd785618574a8e270..521cafcfcb69bb2c5ce13f1f35461541c7b12ccf 100644 (file)
@@ -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;