In order to allow other users to make use of the tp_vec; move it near
the text_poke_bp_batch() code, instead of keeping it in the jump_label
code.

Cc: Daniel Bristot de Oliveira <bris...@redhat.com>
Signed-off-by: Peter Zijlstra (Intel) <pet...@infradead.org>
---
 arch/x86/include/asm/text-patching.h |    4 ++++
 arch/x86/kernel/alternative.c        |    3 +++
 arch/x86/kernel/jump_label.c         |   25 ++++++++++++-------------
 3 files changed, 19 insertions(+), 13 deletions(-)

--- a/arch/x86/include/asm/text-patching.h
+++ b/arch/x86/include/asm/text-patching.h
@@ -60,6 +60,10 @@ extern int after_bootmem;
 extern __ro_after_init struct mm_struct *poking_mm;
 extern __ro_after_init unsigned long poking_addr;
 
+#define TP_VEC_MAX (PAGE_SIZE / sizeof(struct text_poke_loc))
+extern struct text_poke_loc tp_vec[TP_VEC_MAX];
+extern int tp_vec_nr;
+
 #ifndef CONFIG_UML_X86
 static inline void int3_emulate_jmp(struct pt_regs *regs, unsigned long ip)
 {
--- a/arch/x86/kernel/alternative.c
+++ b/arch/x86/kernel/alternative.c
@@ -1017,6 +1017,9 @@ int poke_int3_handler(struct pt_regs *re
 }
 NOKPROBE_SYMBOL(poke_int3_handler);
 
+struct text_poke_loc tp_vec[TP_VEC_MAX];
+int tp_vec_nr;
+
 /**
  * text_poke_bp_batch() -- update instructions on live kernel on SMP
  * @tp:                        vector of instructions to patch
--- a/arch/x86/kernel/jump_label.c
+++ b/arch/x86/kernel/jump_label.c
@@ -100,15 +100,12 @@ void arch_jump_label_transform(struct ju
        mutex_unlock(&text_mutex);
 }
 
-#define TP_VEC_MAX (PAGE_SIZE / sizeof(struct text_poke_loc))
-static struct text_poke_loc tp_vec[TP_VEC_MAX];
-static int tp_vec_nr;
-
 bool arch_jump_label_transform_queue(struct jump_entry *entry,
                                     enum jump_label_type type)
 {
        struct text_poke_loc *tp;
        void *entry_code;
+       bool ret = true;
 
        if (system_state == SYSTEM_BOOTING) {
                /*
@@ -118,12 +115,15 @@ bool arch_jump_label_transform_queue(str
                return true;
        }
 
+       mutex_lock(&text_mutex);
        /*
         * No more space in the vector, tell upper layer to apply
         * the queue before continuing.
         */
-       if (tp_vec_nr == TP_VEC_MAX)
-               return false;
+       if (tp_vec_nr == TP_VEC_MAX) {
+               ret = false;
+               goto unlock;
+       }
 
        tp = &tp_vec[tp_vec_nr];
 
@@ -151,20 +151,19 @@ bool arch_jump_label_transform_queue(str
        text_poke_loc_init(tp, entry_code, NULL, JUMP_LABEL_NOP_SIZE, NULL);
 
        tp_vec_nr++;
+unlock:
+       mutex_unlock(&text_mutex);
 
-       return true;
+       return ret;
 }
 
 void arch_jump_label_transform_apply(void)
 {
-       if (!tp_vec_nr)
-               return;
-
        mutex_lock(&text_mutex);
-       text_poke_bp_batch(tp_vec, tp_vec_nr);
-       mutex_unlock(&text_mutex);
-
+       if (tp_vec_nr)
+               text_poke_bp_batch(tp_vec, tp_vec_nr);
        tp_vec_nr = 0;
+       mutex_unlock(&text_mutex);
 }
 
 static enum {


Reply via email to