Skip to content

Commit 31a099d

Browse files
guoren83willdeacon
authored andcommitted
arm64: patch_text: Fixup last cpu should be master
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. Fixes: ae16480 ("arm64: introduce interfaces to hotpatch kernel and module code") Signed-off-by: Guo Ren <guoren@linux.alibaba.com> Signed-off-by: Guo Ren <guoren@kernel.org> Reviewed-by: Catalin Marinas <catalin.marinas@arm.com> Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org> Cc: <stable@vger.kernel.org> Link: https://lore.kernel.org/r/20220407073323.743224-2-guoren@kernel.org Signed-off-by: Will Deacon <will@kernel.org>
1 parent 697a1d4 commit 31a099d

File tree

1 file changed

+2
-2
lines changed

1 file changed

+2
-2
lines changed

arch/arm64/kernel/patching.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -117,8 +117,8 @@ static int __kprobes aarch64_insn_patch_text_cb(void *arg)
117117
int i, ret = 0;
118118
struct aarch64_insn_patch *pp = arg;
119119

120-
/* The first CPU becomes master */
121-
if (atomic_inc_return(&pp->cpu_count) == 1) {
120+
/* The last CPU becomes master */
121+
if (atomic_inc_return(&pp->cpu_count) == num_online_cpus()) {
122122
for (i = 0; ret == 0 && i < pp->insn_cnt; i++)
123123
ret = aarch64_insn_patch_text_nosync(pp->text_addrs[i],
124124
pp->new_insns[i]);

0 commit comments

Comments
 (0)