* [PATCH V4 0/4] arch: patch_text: Fixup last cpu should be master
@ 2022-04-07 7:33 guoren
2022-04-07 7:33 ` [PATCH V4 1/4] arm64: " guoren
` (4 more replies)
0 siblings, 5 replies; 6+ messages in thread
From: guoren @ 2022-04-07 7:33 UTC (permalink / raw)
To: guoren, arnd, gregkh
Cc: linux-arch, linux-kernel, linux-csky, linux-xtensa, linux-riscv,
linux-arm-kernel, Guo Ren
From: Guo Ren <guoren@linux.alibaba.com>
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(-)
--
2.25.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread
* [PATCH V4 1/4] arm64: patch_text: Fixup last cpu should be master
2022-04-07 7:33 [PATCH V4 0/4] arch: patch_text: Fixup last cpu should be master guoren
@ 2022-04-07 7:33 ` guoren
2022-04-07 7:33 ` [PATCH V4 2/4] riscv: " guoren
` (3 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: guoren @ 2022-04-07 7:33 UTC (permalink / raw)
To: guoren, arnd, gregkh
Cc: linux-arch, linux-kernel, linux-csky, linux-xtensa, linux-riscv,
linux-arm-kernel, Guo Ren, Catalin Marinas, Masami Hiramatsu,
stable
From: Guo Ren <guoren@linux.alibaba.com>
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: ae16480785de ("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>
---
arch/arm64/kernel/patching.c | 4 ++--
1 file changed, 2 insertions(+), 2 deletions(-)
diff --git a/arch/arm64/kernel/patching.c b/arch/arm64/kernel/patching.c
index 771f543464e0..33e0fabc0b79 100644
--- a/arch/arm64/kernel/patching.c
+++ b/arch/arm64/kernel/patching.c
@@ -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]);
--
2.25.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH V4 2/4] riscv: patch_text: Fixup last cpu should be master
2022-04-07 7:33 [PATCH V4 0/4] arch: patch_text: Fixup last cpu should be master guoren
2022-04-07 7:33 ` [PATCH V4 1/4] arm64: " guoren
@ 2022-04-07 7:33 ` guoren
2022-04-07 7:33 ` [PATCH V4 3/4] xtensa: " guoren
` (2 subsequent siblings)
4 siblings, 0 replies; 6+ messages in thread
From: guoren @ 2022-04-07 7:33 UTC (permalink / raw)
To: guoren, arnd, gregkh
Cc: linux-arch, linux-kernel, linux-csky, linux-xtensa, linux-riscv,
linux-arm-kernel, Guo Ren, Masami Hiramatsu, stable
From: Guo Ren <guoren@linux.alibaba.com>
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: 043cb41a85de ("riscv: introduce interfaces to patch kernel code")
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: <stable@vger.kernel.org>
---
arch/riscv/kernel/patch.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/riscv/kernel/patch.c b/arch/riscv/kernel/patch.c
index 0b552873a577..765004b60513 100644
--- a/arch/riscv/kernel/patch.c
+++ b/arch/riscv/kernel/patch.c
@@ -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));
--
2.25.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH V4 3/4] xtensa: patch_text: Fixup last cpu should be master
2022-04-07 7:33 [PATCH V4 0/4] arch: patch_text: Fixup last cpu should be master guoren
2022-04-07 7:33 ` [PATCH V4 1/4] arm64: " guoren
2022-04-07 7:33 ` [PATCH V4 2/4] riscv: " guoren
@ 2022-04-07 7:33 ` guoren
2022-04-07 7:33 ` [PATCH V4 4/4] csky: " guoren
2022-04-08 13:58 ` [PATCH V4 0/4] arch: " Will Deacon
4 siblings, 0 replies; 6+ messages in thread
From: guoren @ 2022-04-07 7:33 UTC (permalink / raw)
To: guoren, arnd, gregkh
Cc: linux-arch, linux-kernel, linux-csky, linux-xtensa, linux-riscv,
linux-arm-kernel, Guo Ren, Max Filippov, Masami Hiramatsu, stable
From: Guo Ren <guoren@linux.alibaba.com>
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: 64711f9a47d4 ("xtensa: implement jump_label support")
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
Reviewed-by: Max Filippov <jcmvbkbc@gmail.com>
Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: <stable@vger.kernel.org>
---
arch/xtensa/kernel/jump_label.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/xtensa/kernel/jump_label.c b/arch/xtensa/kernel/jump_label.c
index 0dde21e0d3de..ad1841cecdfb 100644
--- a/arch/xtensa/kernel/jump_label.c
+++ b/arch/xtensa/kernel/jump_label.c
@@ -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 {
--
2.25.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 6+ messages in thread
* [PATCH V4 4/4] csky: patch_text: Fixup last cpu should be master
2022-04-07 7:33 [PATCH V4 0/4] arch: patch_text: Fixup last cpu should be master guoren
` (2 preceding siblings ...)
2022-04-07 7:33 ` [PATCH V4 3/4] xtensa: " guoren
@ 2022-04-07 7:33 ` guoren
2022-04-08 13:58 ` [PATCH V4 0/4] arch: " Will Deacon
4 siblings, 0 replies; 6+ messages in thread
From: guoren @ 2022-04-07 7:33 UTC (permalink / raw)
To: guoren, arnd, gregkh
Cc: linux-arch, linux-kernel, linux-csky, linux-xtensa, linux-riscv,
linux-arm-kernel, Guo Ren, Masami Hiramatsu, stable
From: Guo Ren <guoren@linux.alibaba.com>
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: 33e53ae1ce41 ("csky: Add kprobes supported")
Signed-off-by: Guo Ren <guoren@linux.alibaba.com>
Signed-off-by: Guo Ren <guoren@kernel.org>
Reviewed-by: Masami Hiramatsu <mhiramat@kernel.org>
Cc: <stable@vger.kernel.org>
---
arch/csky/kernel/probes/kprobes.c | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/arch/csky/kernel/probes/kprobes.c b/arch/csky/kernel/probes/kprobes.c
index 42920f25e73c..34ba684d5962 100644
--- a/arch/csky/kernel/probes/kprobes.c
+++ b/arch/csky/kernel/probes/kprobes.c
@@ -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);
--
2.25.1
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply related [flat|nested] 6+ messages in thread
* Re: [PATCH V4 0/4] arch: patch_text: Fixup last cpu should be master
2022-04-07 7:33 [PATCH V4 0/4] arch: patch_text: Fixup last cpu should be master guoren
` (3 preceding siblings ...)
2022-04-07 7:33 ` [PATCH V4 4/4] csky: " guoren
@ 2022-04-08 13:58 ` Will Deacon
4 siblings, 0 replies; 6+ messages in thread
From: Will Deacon @ 2022-04-08 13:58 UTC (permalink / raw)
To: gregkh, guoren, arnd
Cc: catalin.marinas, kernel-team, Will Deacon, linux-riscv,
linux-kernel, linux-arm-kernel, linux-arch, linux-xtensa, Guo Ren,
linux-csky
On Thu, 7 Apr 2022 15:33:19 +0800, guoren@kernel.org wrote:
> From: Guo Ren <guoren@linux.alibaba.com>
>
> 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.
>
> [...]
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,
--
Will
https://fixes.arm64.dev
https://next.arm64.dev
https://will.arm64.dev
_______________________________________________
linux-arm-kernel mailing list
linux-arm-kernel@lists.infradead.org
http://lists.infradead.org/mailman/listinfo/linux-arm-kernel
^ permalink raw reply [flat|nested] 6+ messages in thread
end of thread, other threads:[~2022-04-08 14:00 UTC | newest]
Thread overview: 6+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2022-04-07 7:33 [PATCH V4 0/4] arch: patch_text: Fixup last cpu should be master guoren
2022-04-07 7:33 ` [PATCH V4 1/4] arm64: " guoren
2022-04-07 7:33 ` [PATCH V4 2/4] riscv: " guoren
2022-04-07 7:33 ` [PATCH V4 3/4] xtensa: " guoren
2022-04-07 7:33 ` [PATCH V4 4/4] csky: " guoren
2022-04-08 13:58 ` [PATCH V4 0/4] arch: " Will Deacon
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).