There are only two types of poking: early and breakpoint based. The use
of a function pointer to perform poking complicates the code and is
probably inefficient due to the use of indirect branches.

Cc: Andy Lutomirski <l...@kernel.org>
Cc: Kees Cook <keesc...@chromium.org>
Cc: Peter Zijlstra <pet...@infradead.org>
Cc: Dave Hansen <dave.han...@intel.com>
Cc: Masami Hiramatsu <mhira...@kernel.org>
Signed-off-by: Nadav Amit <na...@vmware.com>
---
 arch/x86/kernel/jump_label.c | 17 +++++++----------
 1 file changed, 7 insertions(+), 10 deletions(-)

diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
index ed5fe274a7d8..7947df599e58 100644
--- a/arch/x86/kernel/jump_label.c
+++ b/arch/x86/kernel/jump_label.c
@@ -39,13 +39,13 @@ static void bug_at(unsigned char *ip, int line)
 
 static void __ref __jump_label_transform(struct jump_entry *entry,
                                         enum jump_label_type type,
-                                        void *(*poker)(void *, const void *, 
size_t),
                                         int init)
 {
        union jump_code_union jmp;
        const unsigned char default_nop[] = { STATIC_KEY_INIT_NOP };
        const unsigned char *ideal_nop = ideal_nops[NOP_ATOMIC5];
        const void *expect, *code;
+       bool early_poking = init;
        int line;
 
        jmp.jump = 0xe9;
@@ -58,7 +58,7 @@ static void __ref __jump_label_transform(struct jump_entry 
*entry,
         * SYSTEM_SCHEDULING before going either.
         */
        if (system_state == SYSTEM_BOOTING)
-               poker = text_poke_early;
+               early_poking = true;
 
        if (type == JUMP_LABEL_JMP) {
                if (init) {
@@ -82,16 +82,13 @@ static void __ref __jump_label_transform(struct jump_entry 
*entry,
                bug_at((void *)jump_entry_code(entry), line);
 
        /*
-        * Make text_poke_bp() a default fallback poker.
-        *
         * At the time the change is being done, just ignore whether we
         * are doing nop -> jump or jump -> nop transition, and assume
         * always nop being the 'currently valid' instruction
-        *
         */
-       if (poker) {
-               (*poker)((void *)jump_entry_code(entry), code,
-                        JUMP_LABEL_NOP_SIZE);
+       if (early_poking) {
+               text_poke_early((void *)jump_entry_code(entry), code,
+                               JUMP_LABEL_NOP_SIZE);
                return;
        }
 
@@ -103,7 +100,7 @@ void arch_jump_label_transform(struct jump_entry *entry,
                               enum jump_label_type type)
 {
        mutex_lock(&text_mutex);
-       __jump_label_transform(entry, type, NULL, 0);
+       __jump_label_transform(entry, type, 0);
        mutex_unlock(&text_mutex);
 }
 
@@ -133,7 +130,7 @@ __init_or_module void 
arch_jump_label_transform_static(struct jump_entry *entry,
                        jlstate = JL_STATE_NO_UPDATE;
        }
        if (jlstate == JL_STATE_UPDATE)
-               __jump_label_transform(entry, type, text_poke_early, 1);
+               __jump_label_transform(entry, type, 1);
 }
 
 #endif
-- 
2.17.1

Reply via email to