2021-05-06 20:23:24

by Peter Zijlstra

[permalink] [raw]
Subject: [PATCH 06/13] jump_label, x86: Introduce jump_entry_size()

This allows architectures to have variable sized jumps.

Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
---
arch/x86/include/asm/jump_label.h | 4 ++--
arch/x86/kernel/jump_label.c | 7 +++++++
include/linux/jump_label.h | 9 +++++++++
kernel/jump_label.c | 2 +-
4 files changed, 19 insertions(+), 3 deletions(-)

--- a/arch/x86/include/asm/jump_label.h
+++ b/arch/x86/include/asm/jump_label.h
@@ -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 @@ static __always_inline bool arch_static_
return true;
}

+extern int arch_jump_entry_size(struct jump_entry *entry);
+
#endif /* __ASSEMBLY__ */

#endif
--- a/arch/x86/kernel/jump_label.c
+++ b/arch/x86/kernel/jump_label.c
@@ -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)
{
--- a/include/linux/jump_label.h
+++ b/include/linux/jump_label.h
@@ -176,6 +176,15 @@ static inline void jump_entry_set_init(s
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

--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -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;



2021-05-12 13:24:34

by tip-bot2 for Haifeng Xu

[permalink] [raw]
Subject: [tip: objtool/core] jump_label, x86: Introduce jump_entry_size()

The following commit has been merged into the objtool/core branch of tip:

Commit-ID: fa5e5dc39669b4427830c546ede8709323b8276c
Gitweb: https://git.kernel.org/tip/fa5e5dc39669b4427830c546ede8709323b8276c
Author: Peter Zijlstra <[email protected]>
AuthorDate: Thu, 06 May 2021 21:33:58 +02:00
Committer: Ingo Molnar <[email protected]>
CommitterDate: Wed, 12 May 2021 14:54:55 +02:00

jump_label, x86: Introduce jump_entry_size()

This allows architectures to have variable sized jumps.

Signed-off-by: Peter Zijlstra (Intel) <[email protected]>
Signed-off-by: Ingo Molnar <[email protected]>
Link: https://lore.kernel.org/r/[email protected]
---
arch/x86/include/asm/jump_label.h | 4 ++--
arch/x86/kernel/jump_label.c | 7 +++++++
include/linux/jump_label.h | 9 +++++++++
kernel/jump_label.c | 2 +-
4 files changed, 19 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_label.h
index dfdc2b1..d85802a 100644
--- a/arch/x86/include/asm/jump_label.h
+++ b/arch/x86/include/asm/jump_label.h
@@ -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
diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
index 638d3b9..a29eecc 100644
--- a/arch/x86/kernel/jump_label.c
+++ b/arch/x86/kernel/jump_label.c
@@ -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)
{
diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h
index 05f5554..8c45f58 100644
--- a/include/linux/jump_label.h
+++ b/include/linux/jump_label.h
@@ -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

diff --git a/kernel/jump_label.c b/kernel/jump_label.c
index ba39fbb..521cafc 100644
--- a/kernel/jump_label.c
+++ b/kernel/jump_label.c
@@ -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;