From nobody Mon Apr 6 00:32:02 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B506C54EE9 for ; Tue, 13 Sep 2022 03:38:51 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229703AbiIMDit (ORCPT ); Mon, 12 Sep 2022 23:38:49 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55714 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229830AbiIMDib (ORCPT ); Mon, 12 Sep 2022 23:38:31 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id ECB2E54651; Mon, 12 Sep 2022 20:38:27 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MRTb322LvzNmF7; Tue, 13 Sep 2022 11:33:51 +0800 (CST) Received: from huawei.com (10.67.174.53) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 13 Sep 2022 11:38:25 +0800 From: Liao Chang To: , , , , , , , , , , CC: , , , Subject: [PATCH V2 1/3] riscv/kprobe: Optimize the performance of patching single-step slot Date: Tue, 13 Sep 2022 11:34:52 +0800 Message-ID: <20220913033454.104519-2-liaochang1@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220913033454.104519-1-liaochang1@huawei.com> References: <20220913033454.104519-1-liaochang1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.174.53] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Single-step slot would not be used until kprobe is enabled, that means no race condition occurs on it under SMP, hence it is safe to pacth ss slot without stopping machine. Signed-off-by: Liao Chang Acked-by: Masami Hiramatsu (Google) --- arch/riscv/kernel/probes/kprobes.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/arch/riscv/kernel/probes/kprobes.c b/arch/riscv/kernel/probes/= kprobes.c index e6e950b7cf32..bc1f39b96e41 100644 --- a/arch/riscv/kernel/probes/kprobes.c +++ b/arch/riscv/kernel/probes/kprobes.c @@ -24,12 +24,14 @@ post_kprobe_handler(struct kprobe *, struct kprobe_ctlb= lk *, struct pt_regs *); static void __kprobes arch_prepare_ss_slot(struct kprobe *p) { unsigned long offset =3D GET_INSN_LENGTH(p->opcode); + kprobe_opcode_t slot[MAX_INSN_SIZE]; =20 p->ainsn.api.restore =3D (unsigned long)p->addr + offset; =20 - patch_text(p->ainsn.api.insn, p->opcode); - patch_text((void *)((unsigned long)(p->ainsn.api.insn) + offset), - __BUG_INSN_32); + memcpy(slot, &p->opcode, offset); + *(kprobe_opcode_t *)((unsigned long)slot + offset) =3D __BUG_INSN_32; + patch_text_nosync(p->ainsn.api.insn, slot, + offset + GET_INSN_LENGTH(__BUG_INSN_32)); } =20 static void __kprobes arch_prepare_simulate(struct kprobe *p) --=20 2.17.1 From nobody Mon Apr 6 00:32:02 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 32A61C54EE9 for ; Tue, 13 Sep 2022 03:38:46 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230150AbiIMDio (ORCPT ); Mon, 12 Sep 2022 23:38:44 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55716 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229932AbiIMDib (ORCPT ); Mon, 12 Sep 2022 23:38:31 -0400 Received: from szxga03-in.huawei.com (szxga03-in.huawei.com [45.249.212.189]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id CAFA554653; Mon, 12 Sep 2022 20:38:28 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.53]) by szxga03-in.huawei.com (SkyGuard) with ESMTP id 4MRTf16HnPzHntv; Tue, 13 Sep 2022 11:36:25 +0800 (CST) Received: from huawei.com (10.67.174.53) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 13 Sep 2022 11:38:25 +0800 From: Liao Chang To: , , , , , , , , , , CC: , , , Subject: [PATCH V2 2/3] csky/kprobe: Optimize the performance of patching single-step slot Date: Tue, 13 Sep 2022 11:34:53 +0800 Message-ID: <20220913033454.104519-3-liaochang1@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220913033454.104519-1-liaochang1@huawei.com> References: <20220913033454.104519-1-liaochang1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.174.53] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Single-step slot would not be used until kprobe is enabled, that means no race condition occurs on it under SMP, hence it is safe to pacth ss slot without stopping machine. Signed-off-by: Liao Chang Acked-by: Masami Hiramatsu (Google) --- arch/csky/kernel/probes/kprobes.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/csky/kernel/probes/kprobes.c b/arch/csky/kernel/probes/kp= robes.c index 3c6e5c725d81..4feb5ce16264 100644 --- a/arch/csky/kernel/probes/kprobes.c +++ b/arch/csky/kernel/probes/kprobes.c @@ -57,7 +57,11 @@ static void __kprobes arch_prepare_ss_slot(struct kprobe= *p) =20 p->ainsn.api.restore =3D (unsigned long)p->addr + offset; =20 - patch_text(p->ainsn.api.insn, p->opcode); + memcpy(p->ainsn.api.insn, &p->opcode, offset); + dcache_wb_range((unsigned long)p->ainsn.api.insn, + (unsigned long)p->ainsn.api.insn + offset); + icache_inv_range((unsigned long)p->ainsn.api.insn, + (unsigned long)p->ainsn.api.insn + offset); } =20 static void __kprobes arch_prepare_simulate(struct kprobe *p) --=20 2.17.1 From nobody Mon Apr 6 00:32:02 2026 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7C0C9C54EE9 for ; Tue, 13 Sep 2022 03:38:42 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230123AbiIMDij (ORCPT ); Mon, 12 Sep 2022 23:38:39 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:55718 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229984AbiIMDib (ORCPT ); Mon, 12 Sep 2022 23:38:31 -0400 Received: from szxga02-in.huawei.com (szxga02-in.huawei.com [45.249.212.188]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4298C54656; Mon, 12 Sep 2022 20:38:29 -0700 (PDT) Received: from kwepemi500012.china.huawei.com (unknown [172.30.72.55]) by szxga02-in.huawei.com (SkyGuard) with ESMTP id 4MRTc36KtyzmV5w; Tue, 13 Sep 2022 11:34:43 +0800 (CST) Received: from huawei.com (10.67.174.53) by kwepemi500012.china.huawei.com (7.221.188.12) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Tue, 13 Sep 2022 11:38:26 +0800 From: Liao Chang To: , , , , , , , , , , CC: , , , Subject: [PATCH V2 3/3] arm64/kprobe: Optimize the performance of patching single-step slot Date: Tue, 13 Sep 2022 11:34:54 +0800 Message-ID: <20220913033454.104519-4-liaochang1@huawei.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20220913033454.104519-1-liaochang1@huawei.com> References: <20220913033454.104519-1-liaochang1@huawei.com> MIME-Version: 1.0 X-Originating-IP: [10.67.174.53] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To kwepemi500012.china.huawei.com (7.221.188.12) X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Transfer-Encoding: quoted-printable Content-Type: text/plain; charset="utf-8" Single-step slot would not be used until kprobe is enabled, that means no race condition occurs on it under SMP, hence it is safe to pacth ss slot without stopping machine. Signed-off-by: Liao Chang Acked-by: Masami Hiramatsu (Google) --- arch/arm64/kernel/probes/kprobes.c | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/arch/arm64/kernel/probes/kprobes.c b/arch/arm64/kernel/probes/= kprobes.c index d1d182320245..5902e33fd3b6 100644 --- a/arch/arm64/kernel/probes/kprobes.c +++ b/arch/arm64/kernel/probes/kprobes.c @@ -44,11 +44,10 @@ post_kprobe_handler(struct kprobe *, struct kprobe_ctlb= lk *, struct pt_regs *); static void __kprobes arch_prepare_ss_slot(struct kprobe *p) { kprobe_opcode_t *addr =3D p->ainsn.api.insn; - void *addrs[] =3D {addr, addr + 1}; - u32 insns[] =3D {p->opcode, BRK64_OPCODE_KPROBES_SS}; =20 /* prepare insn slot */ - aarch64_insn_patch_text(addrs, insns, 2); + aarch64_insn_write(addr, p->opcode); + aarch64_insn_write(addr + 1, BRK64_OPCODE_KPROBES_SS); =20 flush_icache_range((uintptr_t)addr, (uintptr_t)(addr + MAX_INSN_SIZE)); =20 --=20 2.17.1