arch: patch_text: Fixup last cpu should be master
Subsystems (7)
[email protected]
maintainerv4 cover arch: patch_text: Fixup last cpu should be master
From: Guo Ren <[email protected]>
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.
Changes in v4:
- Add "Fixes:" for stable fixup
- Add cover letter for the patch series
Changes in v3:
- Separate the patch for different arch.
Changes in v2:
- Fixup num_online_cpus() - 1 is not last cpu
Guo Ren (4):
arm64: patch_text: Fixup last cpu should be master
riscv: patch_text: Fixup last cpu should be master
xtensa: patch_text: Fixup last cpu should be master
csky: patch_text: Fixup last cpu should be master
arch/arm64/kernel/patching.c | 4 ++-- arch/csky/kernel/probes/kprobes.c | 2 +- arch/riscv/kernel/patch.c | 2 +- arch/xtensa/kernel/jump_label.c | 2 +- 4 files changed, 5 insertions(+), 5 deletions(-)
Signature · 1 line
2.25.1
[email protected]
maintainerPATCH v4 1/4 arm64: patch_text: Fixup last cpu should be master
From: Guo Ren <[email protected]>
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.
--- arch/arm64/kernel/patching.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-)
arch/arm64/kernel/patching.c +2 -2
@@ -117,8 +117,8 @@ static int __kprobes aarch64_insn_patch_text_cb(void *arg)int i, ret =0 ;struct aarch64_insn_patch *pp = arg; -/* The first CPU becomes master */ -if (atomic_inc_return (&pp->cpu_count) ==1 ) { +/* The last CPU becomes master */ +if (atomic_inc_return (&pp->cpu_count) ==num_online_cpus ()) {for (i =0 ; ret ==0 && i < pp->insn_cnt; i++) ret =aarch64_insn_patch_text_nosync (pp->text_addrs[i], pp->new_insns[i]);
Signature · 1 line
2.25.1
[email protected]
maintainerPATCH v4 2/4 riscv: patch_text: Fixup last cpu should be master
In reply to [email protected]From: Guo Ren <[email protected]>
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.
--- arch/riscv/kernel/patch.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/riscv/kernel/patch.c +1 -1
@@ -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));
Signature · 1 line
2.25.1
[email protected]
maintainerPATCH v4 3/4 xtensa: patch_text: Fixup last cpu should be master
In reply to [email protected]From: Guo Ren <[email protected]>
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.
--- arch/xtensa/kernel/jump_label.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/xtensa/kernel/jump_label.c +1 -1
@@ -40,7 +40,7 @@ static int patch_text_stop_machine(void *data) {struct patch *patch = data; -if (atomic_inc_return (&patch->cpu_count) ==1 ) { +if (atomic_inc_return (&patch->cpu_count) ==num_online_cpus ()) {local_patch_text (patch->addr, patch->data, patch->sz);atomic_inc (&patch->cpu_count); }else {
Signature · 1 line
2.25.1
[email protected]
maintainerPATCH v4 4/4 csky: patch_text: Fixup last cpu should be master
In reply to [email protected]From: Guo Ren <[email protected]>
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.
--- arch/csky/kernel/probes/kprobes.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-)
arch/csky/kernel/probes/kprobes.c +1 -1
@@ -30,7 +30,7 @@ static int __kprobes patch_text_cb(void *priv)struct csky_insn_patch *param = priv;unsigned int addr = (unsigned int )param->addr; -if (atomic_inc_return (¶m->cpu_count) ==1 ) { +if (atomic_inc_return (¶m->cpu_count) ==num_online_cpus ()) { *(u16 *) addr =cpu_to_le16 (param->opcode);dcache_wb_range (addr, addr +2 );atomic_inc (¶m->cpu_count);
Signature · 1 line
2.25.1
Will Deacon
maintainerQuoted 10 lines · On Thu, 7 Apr 2022 15:33:19 +0800, [email protected] wrote:
From: Guo Ren <[email protected]>
These
patch_textimplementations are usingstop_machine_cpuslockedinfrastructure with atomiccpu_count. The original idea: When the master CPUpatch_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.[...]
Applied first patch only to arm64 (for-next/fixes), thanks!
[1/4] arm64: patch_text: Fixup last cpu should be master
https://git.kernel.org/arm64/c/31a099dbd91e
Cheers,
Signature · 5 lines
Will https://fixes.arm64.dev https://next.arm64.dev https://will.arm64.dev