]> git.kernelconcepts.de Git - karo-tx-linux.git/blobdiff - arch/arm64/kernel/alternative.c
Merge tag 'for_linus' of git://git.kernel.org/pub/scm/linux/kernel/git/mst/vhost
[karo-tx-linux.git] / arch / arm64 / kernel / alternative.c
index 221b98312f0c6a7fa7977ec61cef316c89a529e7..ab9db0e9818c0caa52aa040b7c01aa83183d774e 100644 (file)
@@ -85,7 +85,7 @@ static u32 get_alt_insn(struct alt_instr *alt, u32 *insnptr, u32 *altinsnptr)
        return insn;
 }
 
-static int __apply_alternatives(void *alt_region)
+static void __apply_alternatives(void *alt_region)
 {
        struct alt_instr *alt;
        struct alt_region *region = alt_region;
@@ -114,19 +114,39 @@ static int __apply_alternatives(void *alt_region)
                flush_icache_range((uintptr_t)origptr,
                                   (uintptr_t)(origptr + nr_inst));
        }
-
-       return 0;
 }
 
-void apply_alternatives_all(void)
+/*
+ * We might be patching the stop_machine state machine, so implement a
+ * really simple polling protocol here.
+ */
+static int __apply_alternatives_multi_stop(void *unused)
 {
+       static int patched = 0;
        struct alt_region region = {
                .begin  = __alt_instructions,
                .end    = __alt_instructions_end,
        };
 
+       /* We always have a CPU 0 at this point (__init) */
+       if (smp_processor_id()) {
+               while (!READ_ONCE(patched))
+                       cpu_relax();
+               isb();
+       } else {
+               BUG_ON(patched);
+               __apply_alternatives(&region);
+               /* Barriers provided by the cache flushing */
+               WRITE_ONCE(patched, 1);
+       }
+
+       return 0;
+}
+
+void __init apply_alternatives_all(void)
+{
        /* better not try code patching on a live SMP system */
-       stop_machine(__apply_alternatives, &region, NULL);
+       stop_machine(__apply_alternatives_multi_stop, NULL, cpu_online_mask);
 }
 
 void apply_alternatives(void *start, size_t length)