jump_label: make initial NOP patching the special case
authorArd Biesheuvel <ardb@kernel.org>
Wed, 15 Jun 2022 15:41:42 +0000 (17:41 +0200)
committerPeter Zijlstra <peterz@infradead.org>
Fri, 24 Jun 2022 07:48:55 +0000 (09:48 +0200)
Instead of defaulting to patching NOP opcodes at init time, and leaving
it to the architectures to override this if this is not needed, switch
to a model where doing nothing is the default. This is the common case
by far, as only MIPS requires NOP patching at init time. On all other
architectures, the correct encodings are emitted by the compiler and so
no initial patching is needed.

Signed-off-by: Ard Biesheuvel <ardb@kernel.org>
Signed-off-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Acked-by: Mark Rutland <mark.rutland@arm.com>
Acked-by: Peter Zijlstra (Intel) <peterz@infradead.org>
Link: https://lore.kernel.org/r/20220615154142.1574619-4-ardb@kernel.org
Documentation/staging/static-keys.rst
arch/arc/kernel/jump_label.c
arch/arm/kernel/jump_label.c
arch/arm64/kernel/jump_label.c
arch/mips/include/asm/jump_label.h
arch/parisc/kernel/jump_label.c
arch/riscv/kernel/jump_label.c
arch/s390/kernel/jump_label.c
arch/x86/kernel/jump_label.c
include/linux/jump_label.h
kernel/jump_label.c

index 38290b9f25eb25a0c20f7a674c17afa6eb5d1892..b0a519f456cfa37560a7ae97ce7c913724204d93 100644 (file)
@@ -201,9 +201,6 @@ static_key->entry field makes use of the two least significant bits.
 * ``void arch_jump_label_transform(struct jump_entry *entry, enum jump_label_type type)``,
     see: arch/x86/kernel/jump_label.c
 
-* ``__init_or_module void arch_jump_label_transform_static(struct jump_entry *entry, enum jump_label_type type)``,
-    see: arch/x86/kernel/jump_label.c
-
 * ``struct jump_entry``,
     see: arch/x86/include/asm/jump_label.h
 
index b8600dc325b5aa6db4f0d2cfa65f3139c713640b..70b74a5d047b75a6b495c323c625ee1dee9bdc05 100644 (file)
@@ -96,19 +96,6 @@ void arch_jump_label_transform(struct jump_entry *entry,
        flush_icache_range(entry->code, entry->code + JUMP_LABEL_NOP_SIZE);
 }
 
-void arch_jump_label_transform_static(struct jump_entry *entry,
-                                     enum jump_label_type type)
-{
-       /*
-        * We use only one NOP type (1x, 4 byte) in arch_static_branch, so
-        * there's no need to patch an identical NOP over the top of it here.
-        * The generic code calls 'arch_jump_label_transform' if the NOP needs
-        * to be replaced by a branch, so 'arch_jump_label_transform_static' is
-        * never called with type other than JUMP_LABEL_NOP.
-        */
-       BUG_ON(type != JUMP_LABEL_NOP);
-}
-
 #ifdef CONFIG_ARC_DBG_JUMP_LABEL
 #define SELFTEST_MSG   "ARC: instruction generation self-test: "
 
index 303b3ab87f7e892a4607055eae136582372745cf..eb9c24b6e8e23a6d04ba88e35ca4e8adb295f3b1 100644 (file)
@@ -27,9 +27,3 @@ void arch_jump_label_transform(struct jump_entry *entry,
 {
        __arch_jump_label_transform(entry, type, false);
 }
-
-void arch_jump_label_transform_static(struct jump_entry *entry,
-                                     enum jump_label_type type)
-{
-       __arch_jump_label_transform(entry, type, true);
-}
index fc98037e122056057b15693f647d4628feb8229a..faf88ec9c48e8a91487329fffb7f9d20fd3b6854 100644 (file)
@@ -26,14 +26,3 @@ void arch_jump_label_transform(struct jump_entry *entry,
 
        aarch64_insn_patch_text_nosync(addr, insn);
 }
-
-void arch_jump_label_transform_static(struct jump_entry *entry,
-                                     enum jump_label_type type)
-{
-       /*
-        * We use the architected A64 NOP in arch_static_branch, so there's no
-        * need to patch an identical A64 NOP over the top of it here. The core
-        * will call arch_jump_label_transform from a module notifier if the
-        * NOP needs to be replaced by a branch.
-        */
-}
index 3185fd3220ec217d73d320a710f7bd2c5902b757..c5c6864e64bc430a98b2acfce5e4eb13b16dee0a 100644 (file)
@@ -8,6 +8,8 @@
 #ifndef _ASM_MIPS_JUMP_LABEL_H
 #define _ASM_MIPS_JUMP_LABEL_H
 
+#define arch_jump_label_transform_static arch_jump_label_transform
+
 #ifndef __ASSEMBLY__
 
 #include <linux/types.h>
index d2f3cb12e282030303cf690937650db6c778b18f..e253b134500d1319b576464ddc2a78493ee236d5 100644 (file)
@@ -42,14 +42,3 @@ void arch_jump_label_transform(struct jump_entry *entry,
 
        patch_text(addr, insn);
 }
-
-void arch_jump_label_transform_static(struct jump_entry *entry,
-                                     enum jump_label_type type)
-{
-       /*
-        * We use the architected NOP in arch_static_branch, so there's no
-        * need to patch an identical NOP over the top of it here. The core
-        * will call arch_jump_label_transform from a module notifier if the
-        * NOP needs to be replaced by a branch.
-        */
-}
index 20e09056d141f5d15783daa8dc7037372bb4c1dd..e6694759dbd010f9d8b98a31d854a19a3491e10a 100644 (file)
@@ -39,15 +39,3 @@ void arch_jump_label_transform(struct jump_entry *entry,
        patch_text_nosync(addr, &insn, sizeof(insn));
        mutex_unlock(&text_mutex);
 }
-
-void arch_jump_label_transform_static(struct jump_entry *entry,
-                                     enum jump_label_type type)
-{
-       /*
-        * We use the same instructions in the arch_static_branch and
-        * arch_static_branch_jump inline functions, so there's no
-        * need to patch them up here.
-        * The core will call arch_jump_label_transform  when those
-        * instructions need to be replaced.
-        */
-}
index d764f0d229ab0f66b81eeb049a56a921065abef7..e808bb8bc0da4d02a3cda5c94808d814a0c68d32 100644 (file)
@@ -80,8 +80,3 @@ void arch_jump_label_transform_apply(void)
 {
        text_poke_sync();
 }
-
-void __init_or_module arch_jump_label_transform_static(struct jump_entry *entry,
-                                                      enum jump_label_type type)
-{
-}
index 68f091ba84434bb2ef075bcedebb4ef0c4f59e6b..f5b8ef02d172c1740f4c22a622b188da379f13d9 100644 (file)
@@ -146,16 +146,3 @@ void arch_jump_label_transform_apply(void)
        text_poke_finish();
        mutex_unlock(&text_mutex);
 }
-
-static enum {
-       JL_STATE_START,
-       JL_STATE_NO_UPDATE,
-       JL_STATE_UPDATE,
-} jlstate __initdata_or_module = JL_STATE_START;
-
-__init_or_module void arch_jump_label_transform_static(struct jump_entry *entry,
-                                     enum jump_label_type type)
-{
-       if (jlstate == JL_STATE_UPDATE)
-               jump_label_transform(entry, type, 1);
-}
index 2003a093547830f5a14fe7ecf6ffe932402cbc5c..570831ca9951841704f7b371a23029d1d021c1b2 100644 (file)
@@ -220,8 +220,6 @@ extern void jump_label_lock(void);
 extern void jump_label_unlock(void);
 extern void arch_jump_label_transform(struct jump_entry *entry,
                                      enum jump_label_type type);
-extern void arch_jump_label_transform_static(struct jump_entry *entry,
-                                            enum jump_label_type type);
 extern bool arch_jump_label_transform_queue(struct jump_entry *entry,
                                            enum jump_label_type type);
 extern void arch_jump_label_transform_apply(void);
index b1ac2948be797e8509df7fef015c44094d824931..714ac4c3b556de14ab896f45d6d9a905552bb118 100644 (file)
@@ -332,17 +332,13 @@ static int __jump_label_text_reserved(struct jump_entry *iter_start,
        return 0;
 }
 
-/*
- * Update code which is definitely not currently executing.
- * Architectures which need heavyweight synchronization to modify
- * running code can override this to make the non-live update case
- * cheaper.
- */
-void __weak __init_or_module arch_jump_label_transform_static(struct jump_entry *entry,
-                                           enum jump_label_type type)
+#ifndef arch_jump_label_transform_static
+static void arch_jump_label_transform_static(struct jump_entry *entry,
+                                            enum jump_label_type type)
 {
-       arch_jump_label_transform(entry, type);
+       /* nothing to do on most architectures */
 }
+#endif
 
 static inline struct jump_entry *static_key_entries(struct static_key *key)
 {