2021-05-06 20:20:36

by Peter Zijlstra

[permalink] [raw]
Subject: [PATCH 09/13] jump_label,x86: Emit short JMP

Now that we can patch short JMP/NOP, allow the compiler/assembler to
emit short JMP instructions.

There is no way to have the assembler emit short NOPs based on the
potential displacement, so leave those long for now.

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

--- a/arch/x86/include/asm/jump_label.h
+++ b/arch/x86/include/asm/jump_label.h
@@ -35,8 +35,7 @@ static __always_inline bool arch_static_
static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch)
{
asm_volatile_goto("1:"
- ".byte 0xe9 \n\t"
- ".long %l[l_yes] - (. + 4) \n\t"
+ "jmp %l[l_yes]\n\t"
JUMP_TABLE_ENTRY
: : "i" (key), "i" (branch) : : l_yes);

--- a/arch/x86/kernel/jump_label.c
+++ b/arch/x86/kernel/jump_label.c
@@ -15,12 +15,18 @@
#include <asm/kprobes.h>
#include <asm/alternative.h>
#include <asm/text-patching.h>
+#include <asm/insn.h>

#define JUMP_LABEL_NOP_SIZE JMP32_INSN_SIZE

int arch_jump_entry_size(struct jump_entry *entry)
{
- return JMP32_INSN_SIZE;
+ struct insn insn = {};
+
+ insn_decode_kernel(&insn, (void *)jump_entry_code(entry));
+ BUG_ON(insn.length != 2 && insn.length != 5);
+
+ return insn.length;
}

struct jump_label_patch {



2021-05-12 13:25:10

by tip-bot2 for Haifeng Xu

[permalink] [raw]
Subject: [tip: objtool/core] jump_label, x86: Emit short JMP

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

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

jump_label, x86: Emit short JMP

Now that we can patch short JMP/NOP, allow the compiler/assembler to
emit short JMP instructions.

There is no way to have the assembler emit short NOPs based on the
potential displacement, so leave those long for now.

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 | 3 +--
arch/x86/kernel/jump_label.c | 8 +++++++-
2 files changed, 8 insertions(+), 3 deletions(-)

diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_label.h
index d85802a..ef819e3 100644
--- a/arch/x86/include/asm/jump_label.h
+++ b/arch/x86/include/asm/jump_label.h
@@ -35,8 +35,7 @@ l_yes:
static __always_inline bool arch_static_branch_jump(struct static_key * const key, const bool branch)
{
asm_volatile_goto("1:"
- ".byte 0xe9 \n\t"
- ".long %l[l_yes] - (. + 4) \n\t"
+ "jmp %l[l_yes]\n\t"
JUMP_TABLE_ENTRY
: : "i" (key), "i" (branch) : : l_yes);

diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
index 190d810..a762dc1 100644
--- a/arch/x86/kernel/jump_label.c
+++ b/arch/x86/kernel/jump_label.c
@@ -15,12 +15,18 @@
#include <asm/kprobes.h>
#include <asm/alternative.h>
#include <asm/text-patching.h>
+#include <asm/insn.h>

#define JUMP_LABEL_NOP_SIZE JMP32_INSN_SIZE

int arch_jump_entry_size(struct jump_entry *entry)
{
- return JMP32_INSN_SIZE;
+ struct insn insn = {};
+
+ insn_decode_kernel(&insn, (void *)jump_entry_code(entry));
+ BUG_ON(insn.length != 2 && insn.length != 5);
+
+ return insn.length;
}

struct jump_label_patch {