riscv: patch_text: Fixup last cpu should be master
authorGuo Ren <guoren@linux.alibaba.com>
Wed, 6 Apr 2022 14:16:49 +0000 (22:16 +0800)
committerPalmer Dabbelt <palmer@rivosinc.com>
Fri, 22 Apr 2022 15:29:24 +0000 (08:29 -0700)
These patch_text implementations are using stop_machine_cpuslocked
infrastructure with atomic cpu_count. The original idea: When the
master CPU patch_text, the others should wait for it. But current
implementation is using the first CPU as master, which couldn't
guarantee the remaining CPUs are waiting. This patch changes the
last CPU as the master to solve the potential risk.

Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
Acked-by: Palmer Dabbelt <palmer@rivosinc.com>
Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>
Fixes: 043cb41a85de ("riscv: introduce interfaces to patch kernel code")
Cc: stable@vger.kernel.org
Signed-off-by: Palmer Dabbelt <palmer@rivosinc.com>
arch/riscv/kernel/patch.c

index 0b55287..765004b 100644 (file)
@@ -104,7 +104,7 @@ static int patch_text_cb(void *data)
        struct patch_insn *patch = data;
        int ret = 0;
 
-       if (atomic_inc_return(&patch->cpu_count) == 1) {
+       if (atomic_inc_return(&patch->cpu_count) == num_online_cpus()) {
                ret =
                    patch_text_nosync(patch->addr, &patch->insn,
                                            GET_INSN_LENGTH(patch->insn));