mirror of https://lore.kernel.org/lkml/
 help / color / mirror / Atom feed
From: Peter Zijlstra <peterz@infradead.org>
To: x86@kernel.org, peterz@infradead.org, linux-kernel@vger.kernel.org
Cc: Josh Poimboeuf <jpoimboe@redhat.com>,
	Steven Rostedt <rostedt@goodmis.org>,
	Masami Hiramatsu <mhiramat@kernel.org>,
	Daniel Bristot de Oliveira <bristot@redhat.com>,
	Jason Baron <jbaron@akamai.com>, Nadav Amit <namit@vmware.com>,
	Andy Lutomirski <luto@kernel.org>,
	Eugeniy Paltsev <Eugeniy.Paltsev@synopsys.com>,
	Vineet Gupta <Vineet.Gupta1@synopsys.com>
Subject: [RFC][PATCH 7/8] jump_label, x86: Introduce jump_entry_size()
Date: Fri, 28 Jun 2019 12:21:20 +0200	[thread overview]
Message-ID: <20190628103224.830851505@infradead.org> (raw)
In-Reply-To: <20190628102113.360432762@infradead.org>

This allows architectures to have variable sized jumps.

Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
---
 arch/x86/include/asm/jump_label.h |    4 ++--
 arch/x86/kernel/jump_label.c      |    8 ++++++++
 include/linux/jump_label.h        |    9 +++++++++
 kernel/jump_label.c               |    2 +-
 4 files changed, 20 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
-
 #ifdef CONFIG_X86_64
 # define STATIC_KEY_NOP2 P6_NOP2
 # define STATIC_KEY_NOP5 P6_NOP5_ATOMIC
@@ -55,6 +53,8 @@ static __always_inline bool arch_static_
 	return true;
 }
 
+extern int arch_jump_entry_size(struct jump_entry *entry);
+
 #else	/* __ASSEMBLY__ */
 
 .macro STATIC_BRANCH_FALSE_LIKELY target, key
--- a/arch/x86/kernel/jump_label.c
+++ b/arch/x86/kernel/jump_label.c
@@ -32,6 +32,14 @@ static inline bool __jump_disp_is_byte(s
 	return false;
 }
 
+int arch_jump_entry_size(struct jump_entry *entry)
+{
+	s32 disp = jump_entry_target(entry) - jump_entry_code(entry);
+	if (__jump_disp_is_byte(disp))
+		return JMP8_INSN_SIZE;
+	return JMP32_INSN_SIZE;
+}
+
 static int __jump_label_set_jump_code(struct jump_entry *entry,
 				      enum jump_label_type type,
 				      union jump_code_union *code,
--- 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;



  parent reply	other threads:[~2019-06-28 13:36 UTC|newest]

Thread overview: 9+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2019-06-28 10:21 [RFC][PATCH 0/8] jump_label, x86: Support variable sized JMP instructions Peter Zijlstra
2019-06-28 10:21 ` [RFC][PATCH 1/8] x86/alternatives: Teach text_poke_bp() to emulate instructions Peter Zijlstra
2019-06-28 10:21 ` [RFC][PATCH 2/8] jump_label, x86: Strip ASM jump_label support Peter Zijlstra
2019-06-28 10:21 ` [RFC][PATCH 3/8] jump_label, x86: Factor out the __jump_table generation Peter Zijlstra
2019-06-28 10:21 ` [RFC][PATCH 4/8] jump_label, x86: Remove init NOP optimization Peter Zijlstra
2019-06-28 10:21 ` [RFC][PATCH 5/8] jump_label, x86: Improve error when we fail expected text Peter Zijlstra
2019-06-28 10:21 ` [RFC][PATCH 6/8] jump_label, x86: Add variable length patching support Peter Zijlstra
2019-06-28 10:21 ` Peter Zijlstra [this message]
2019-06-28 10:21 ` [RFC][PATCH 8/8] jump_label, x86: Enable JMP8/NOP2 support Peter Zijlstra

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20190628103224.830851505@infradead.org \
    --to=peterz@infradead.org \
    --cc=Eugeniy.Paltsev@synopsys.com \
    --cc=Vineet.Gupta1@synopsys.com \
    --cc=bristot@redhat.com \
    --cc=jbaron@akamai.com \
    --cc=jpoimboe@redhat.com \
    --cc=linux-kernel@vger.kernel.org \
    --cc=luto@kernel.org \
    --cc=mhiramat@kernel.org \
    --cc=namit@vmware.com \
    --cc=rostedt@goodmis.org \
    --cc=x86@kernel.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox

all inboxes | Powered by JetHome®