[<prev] [next>] [<thread-prev] [thread-next>] [day] [month] [year] [list]
Message-ID: <e5a4ef67a5c65d1686e4d0ce1887e045d56ffa41.1746821544.git.jpoimboe@kernel.org>
Date: Fri, 9 May 2025 13:17:08 -0700
From: Josh Poimboeuf <jpoimboe@...nel.org>
To: x86@...nel.org
Cc: linux-kernel@...r.kernel.org,
Petr Mladek <pmladek@...e.com>,
Miroslav Benes <mbenes@...e.cz>,
Joe Lawrence <joe.lawrence@...hat.com>,
live-patching@...r.kernel.org,
Song Liu <song@...nel.org>,
laokz <laokz@...mail.com>,
Jiri Kosina <jikos@...nel.org>,
Marcos Paulo de Souza <mpdesouza@...e.com>,
Weinan Liu <wnliu@...gle.com>,
Fazla Mehrab <a.mehrab@...edance.com>,
Chen Zhongjin <chenzhongjin@...wei.com>,
Puranjay Mohan <puranjay@...nel.org>
Subject: [PATCH v2 44/62] x86/jump_label: Define ELF section entry size for jump table
In preparation for the objtool klp diff subcommand, define the entry
size for the __jump_table section in its ELF header. This will allow
tooling to extract individual entries.
Signed-off-by: Josh Poimboeuf <jpoimboe@...nel.org>
---
arch/x86/include/asm/jump_label.h | 32 +++++++++++++++++--------------
include/linux/jump_label.h | 20 +++++++++++--------
2 files changed, 30 insertions(+), 22 deletions(-)
diff --git a/arch/x86/include/asm/jump_label.h b/arch/x86/include/asm/jump_label.h
index cd21554b3675..6081c33e1566 100644
--- a/arch/x86/include/asm/jump_label.h
+++ b/arch/x86/include/asm/jump_label.h
@@ -12,29 +12,31 @@
#include <linux/stringify.h>
#include <linux/types.h>
-#define JUMP_TABLE_ENTRY(key, label) \
- ".pushsection __jump_table, \"a\"\n\t" \
- _ASM_ALIGN "\n\t" \
- ".long 1b - . \n\t" \
- ".long " label " - . \n\t" \
- _ASM_PTR " " key " - . \n\t" \
+#define JUMP_TABLE_ENTRY(key, label, size) \
+ ".pushsection __jump_table, \"aM\", @progbits, " size "\n\t" \
+ _ASM_ALIGN "\n\t" \
+ ".long 1b - . \n\t" \
+ ".long " label " - . \n\t" \
+ _ASM_PTR " " key " - . \n\t" \
".popsection \n\t"
/* This macro is also expanded on the Rust side. */
#ifdef CONFIG_HAVE_JUMP_LABEL_HACK
-#define ARCH_STATIC_BRANCH_ASM(key, label) \
+#define ARCH_STATIC_BRANCH_ASM(key, label, size) \
"1: jmp " label " # objtool NOPs this \n\t" \
- JUMP_TABLE_ENTRY(key " + 2", label)
+ JUMP_TABLE_ENTRY(key " + 2", label, size)
#else /* !CONFIG_HAVE_JUMP_LABEL_HACK */
-#define ARCH_STATIC_BRANCH_ASM(key, label) \
+#define ARCH_STATIC_BRANCH_ASM(key, label, size) \
"1: .byte " __stringify(BYTES_NOP5) "\n\t" \
- JUMP_TABLE_ENTRY(key, label)
+ JUMP_TABLE_ENTRY(key, label, size)
#endif /* CONFIG_HAVE_JUMP_LABEL_HACK */
static __always_inline bool arch_static_branch(struct static_key * const key, const bool branch)
{
- asm goto(ARCH_STATIC_BRANCH_ASM("%c0 + %c1", "%l[l_yes]")
- : : "i" (key), "i" (branch) : : l_yes);
+ asm goto(ARCH_STATIC_BRANCH_ASM("%c[key] + %c[branch]", "%l[l_yes]", "%c[size]")
+ : : [key] "i" (key), [branch] "i" (branch),
+ [size] "i" (sizeof(struct jump_entry))
+ : : l_yes);
return false;
l_yes:
@@ -45,8 +47,10 @@ static __always_inline bool arch_static_branch_jump(struct static_key * const ke
{
asm goto("1:"
"jmp %l[l_yes]\n\t"
- JUMP_TABLE_ENTRY("%c0 + %c1", "%l[l_yes]")
- : : "i" (key), "i" (branch) : : l_yes);
+ JUMP_TABLE_ENTRY("%c[key] + %c[branch]", "%l[l_yes]", "%c[size]")
+ : : [key] "i" (key), [branch] "i" (branch),
+ [size] "i" (sizeof(struct jump_entry))
+ : : l_yes);
return false;
l_yes:
diff --git a/include/linux/jump_label.h b/include/linux/jump_label.h
index fdb79dd1ebd8..9ff1ecc8e7a8 100644
--- a/include/linux/jump_label.h
+++ b/include/linux/jump_label.h
@@ -110,16 +110,20 @@ struct static_key {
#endif /* __ASSEMBLY__ */
#ifdef CONFIG_JUMP_LABEL
-#include <asm/jump_label.h>
-
-#ifndef __ASSEMBLY__
-#ifdef CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE
+#if defined(CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE) && !defined(__ASSEMBLY__)
+/* Must be defined before including <asm/jump_label.h> */
struct jump_entry {
s32 code;
s32 target;
long key; // key may be far away from the core kernel under KASLR
};
+#endif
+
+#include <asm/jump_label.h>
+
+#ifndef __ASSEMBLY__
+#ifdef CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE
static inline unsigned long jump_entry_code(const struct jump_entry *entry)
{
@@ -138,7 +142,7 @@ static inline struct static_key *jump_entry_key(const struct jump_entry *entry)
return (struct static_key *)((unsigned long)&entry->key + offset);
}
-#else
+#else /* !CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE */
static inline unsigned long jump_entry_code(const struct jump_entry *entry)
{
@@ -155,7 +159,7 @@ static inline struct static_key *jump_entry_key(const struct jump_entry *entry)
return (struct static_key *)((unsigned long)entry->key & ~3UL);
}
-#endif
+#endif /* !CONFIG_HAVE_ARCH_JUMP_LABEL_RELATIVE */
static inline bool jump_entry_is_branch(const struct jump_entry *entry)
{
@@ -184,8 +188,8 @@ static inline int jump_entry_size(struct jump_entry *entry)
#endif
}
-#endif
-#endif
+#endif /* !__ASSEMBLY__ */
+#endif /* CONFIG_JUMP_LABEL */
#ifndef __ASSEMBLY__
--
2.49.0
Powered by blists - more mailing lists