Message ID | 1674007261-9198-5-git-send-email-yangtiezhu@loongson.cn |
---|---|
State | New |
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp2092067wrn; Tue, 17 Jan 2023 18:03:20 -0800 (PST) X-Google-Smtp-Source: AMrXdXtMoE5H3xa9kODCx6p5xwzztQ+Aqyz6PafLeoBGyw+Q0JUyABQwe/FgEGbSXzx/8sYvrTv5 X-Received: by 2002:a05:6a20:8e18:b0:ad:97cc:e957 with SMTP id y24-20020a056a208e1800b000ad97cce957mr37255074pzj.39.1674007399996; Tue, 17 Jan 2023 18:03:19 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1674007399; cv=none; d=google.com; s=arc-20160816; b=HcOfZdeXRna0gQa5LGOGNgqOpxmXts+6I4T4wfkAFINTVvL8a5uPASltoAVme+Fxyg AHT1+w0aV189RTEeSGQW5hGKfiUJbemVpqwZZhShF8AZE6qUNX5kx2Vsq6+SMTFRpcIl uD0K631FftC/S/UaAzwGlGm4VJ+X5sUi85opTaqSvVgWWCfiTOC/ETLAskMI9FpyP6H3 d5a1pC4Ol8Y4j84Awj7XjK4PeGOhiRQEqgiQJARdMrORRm2lGX7qAhkYcLzAiuoCE8MC zf/tojUlwafKjJ0Y5I/1HQGv16P89hUWP2xtYT9GL+UH0YIt7Zu/jE+1+oRRYjwEU+0o fefQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:references:in-reply-to:message-id:date:subject :cc:to:from; bh=MpMeKU/pJxacR3Vppqwm3cbZP3LsFuNbwC615vahZMg=; b=J7zIESd6J6jnC4Gj3yzfM+Quamrxpooi34b05LIVFiQqEwzIw9/FL3TqtBsgVvYD3M xu9rklY2mBP70mn4JI9l++824c0B1ifKByK89UzbbZQjR73mHg43Fohcn3cZVyKUA0Aa HwRVzyO0uO/QgFxlY31/E6jaJoGpe7hSazI7U8uqIliHLyOlv4AXfkmpyCxdsNcWolnG 849G0Yy++q2PTg/JklGUAFV6wSpKUW+UbAHdzHyxAAxq4zptGdlKf+V73DMhhnV2r6Ds 2Lty+ve1Xy3XCV2YwbjaeJvuYoykc875jZUEzSKGHw5Mv23djOvNSSMUOZFDDykIJJcH /BWA== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u11-20020a63234b000000b004a68aefb7adsi34877203pgm.215.2023.01.17.18.03.07; Tue, 17 Jan 2023 18:03:19 -0800 (PST) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229644AbjARCBV (ORCPT <rfc822;pfffrao@gmail.com> + 99 others); Tue, 17 Jan 2023 21:01:21 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:39178 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229588AbjARCBL (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Tue, 17 Jan 2023 21:01:11 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 174334F870 for <linux-kernel@vger.kernel.org>; Tue, 17 Jan 2023 18:01:06 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8BxLuviUsdjTz0CAA--.6819S3; Wed, 18 Jan 2023 10:01:06 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8DxTuTeUsdjPhYbAA--.17049S6; Wed, 18 Jan 2023 10:01:04 +0800 (CST) From: Tiezhu Yang <yangtiezhu@loongson.cn> To: Huacai Chen <chenhuacai@kernel.org>, WANG Xuerui <kernel@xen0n.name>, Masami Hiramatsu <mhiramat@kernel.org> Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v12 4/5] LoongArch: Mark some assembler symbols as non-kprobe-able Date: Wed, 18 Jan 2023 10:01:00 +0800 Message-Id: <1674007261-9198-5-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 In-Reply-To: <1674007261-9198-1-git-send-email-yangtiezhu@loongson.cn> References: <1674007261-9198-1-git-send-email-yangtiezhu@loongson.cn> X-CM-TRANSID: AQAAf8DxTuTeUsdjPhYbAA--.17049S6 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjvJXoW7uw45Wr4fCw45ZrWUGFW7urg_yoW8Kr17pw 1DAr4vgrs5Gr1fJry7tF1UZ3yDZws7Gr12v3W29FW8CF47WF18Zry093yDXFyxtw43GFWF qFn5J3929F4UJa7anT9S1TB71UUUUUUqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b28YFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jrv_JF1l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW5JVW7JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26r4UJVWxJr1l84ACjcxK6I8E87Iv6xkF7I0E14v26r4UJVWxJr1l e2I262IYc4CY6c8Ij28IcVAaY2xG8wAqjxCEc2xF0cIa020Ex4CE44I27wAqx4xG64xvF2 IEw4CE5I8CrVC2j2WlYx0E2Ix0cI8IcVAFwI0_Jw0_WrylYx0Ex4A2jsIE14v26r4j6F4U McvjeVCFs4IE7xkEbVWUJVW8JwACjcxG0xvY0x0EwIxGrwCF04k20xvY0x0EwIxGrwCFx2 IqxVCFs4IE7xkEbVWUJVW8JwC20s026c02F40E14v26r1j6r18MI8I3I0E7480Y4vE14v2 6r106r1rMI8E67AF67kF1VAFwI0_JF0_Jw1lIxkGc2Ij64vIr41lIxAIcVC0I7IYx2IY67 AKxVW8JVW5JwCI42IY6xIIjxv20xvEc7CjxVAFwI0_Gr0_Cr1lIxAIcVCF04k26cxKx2IY s7xG6r1j6r1xMIIF0xvEx4A2jsIE14v26r4j6F4UMIIF0xvEx4A2jsIEc7CjxVAFwI0_Gr 0_Gr1UYxBIdaVFxhVjvjDU0xZFpf9x07josjUUUUUU= X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,SPF_HELO_PASS, SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: <linux-kernel.vger.kernel.org> X-Mailing-List: linux-kernel@vger.kernel.org X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1755323983883343913?= X-GMAIL-MSGID: =?utf-8?q?1755323983883343913?= |
Series |
Add kprobe and kretprobe support for LoongArch
|
|
Commit Message
Tiezhu Yang
Jan. 18, 2023, 2:01 a.m. UTC
Some assembler symbols are not kprobe safe, such as handle_syscall
(used as syscall exception handler), *memcpy* (may cause recursive
exceptions), they can not be instrumented, just blacklist them for
kprobing.
Here is a related problem and discussion:
Link: https://lore.kernel.org/lkml/20230114143859.7ccc45c1c5d9ce302113ab0a@kernel.org/
Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn>
---
arch/loongarch/include/asm/asm.h | 10 ++++++++++
arch/loongarch/kernel/entry.S | 1 +
arch/loongarch/lib/memcpy.S | 3 +++
3 files changed, 14 insertions(+)
Comments
If memcpy should be blacklisted, then what about memset and memmove? Huacai On Wed, Jan 18, 2023 at 10:01 AM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: > > Some assembler symbols are not kprobe safe, such as handle_syscall > (used as syscall exception handler), *memcpy* (may cause recursive > exceptions), they can not be instrumented, just blacklist them for > kprobing. > > Here is a related problem and discussion: > Link: https://lore.kernel.org/lkml/20230114143859.7ccc45c1c5d9ce302113ab0a@kernel.org/ > > Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> > --- > arch/loongarch/include/asm/asm.h | 10 ++++++++++ > arch/loongarch/kernel/entry.S | 1 + > arch/loongarch/lib/memcpy.S | 3 +++ > 3 files changed, 14 insertions(+) > > diff --git a/arch/loongarch/include/asm/asm.h b/arch/loongarch/include/asm/asm.h > index 40eea6a..f591b32 100644 > --- a/arch/loongarch/include/asm/asm.h > +++ b/arch/loongarch/include/asm/asm.h > @@ -188,4 +188,14 @@ > #define PTRLOG 3 > #endif > > +/* Annotate a function as being unsuitable for kprobes. */ > +#ifdef CONFIG_KPROBES > +#define _ASM_NOKPROBE(name) \ > + .pushsection "_kprobe_blacklist", "aw"; \ > + .quad name; \ > + .popsection > +#else > +#define _ASM_NOKPROBE(name) > +#endif > + > #endif /* __ASM_ASM_H */ > diff --git a/arch/loongarch/kernel/entry.S b/arch/loongarch/kernel/entry.S > index d53b631..55e23b1 100644 > --- a/arch/loongarch/kernel/entry.S > +++ b/arch/loongarch/kernel/entry.S > @@ -67,6 +67,7 @@ SYM_FUNC_START(handle_syscall) > > RESTORE_ALL_AND_RET > SYM_FUNC_END(handle_syscall) > +_ASM_NOKPROBE(handle_syscall) > > SYM_CODE_START(ret_from_fork) > bl schedule_tail # a0 = struct task_struct *prev > diff --git a/arch/loongarch/lib/memcpy.S b/arch/loongarch/lib/memcpy.S > index 7c07d59..3b7e1de 100644 > --- a/arch/loongarch/lib/memcpy.S > +++ b/arch/loongarch/lib/memcpy.S > @@ -17,6 +17,7 @@ SYM_FUNC_START(memcpy) > ALTERNATIVE "b __memcpy_generic", \ > "b __memcpy_fast", CPU_FEATURE_UAL > SYM_FUNC_END(memcpy) > +_ASM_NOKPROBE(memcpy) > > EXPORT_SYMBOL(memcpy) > > @@ -41,6 +42,7 @@ SYM_FUNC_START(__memcpy_generic) > 2: move a0, a3 > jr ra > SYM_FUNC_END(__memcpy_generic) > +_ASM_NOKPROBE(__memcpy_generic) > > /* > * void *__memcpy_fast(void *dst, const void *src, size_t n) > @@ -93,3 +95,4 @@ SYM_FUNC_START(__memcpy_fast) > 3: move a0, a3 > jr ra > SYM_FUNC_END(__memcpy_fast) > +_ASM_NOKPROBE(__memcpy_fast) > -- > 2.1.0 >
On 01/18/2023 12:14 PM, Huacai Chen wrote: > If memcpy should be blacklisted, then what about memset and memmove? According to the test results, there are no problems to probe memset and memmove, so no need to blacklist them for now, blacklist memcpy is because it may cause recursive exceptions, there is a detailed discussion in the following link: https://lore.kernel.org/lkml/20230114143859.7ccc45c1c5d9ce302113ab0a@kernel.org/ Thanks, Tiezhu > > Huacai > > On Wed, Jan 18, 2023 at 10:01 AM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: >> >> Some assembler symbols are not kprobe safe, such as handle_syscall >> (used as syscall exception handler), *memcpy* (may cause recursive >> exceptions), they can not be instrumented, just blacklist them for >> kprobing. >> >> Here is a related problem and discussion: >> Link: https://lore.kernel.org/lkml/20230114143859.7ccc45c1c5d9ce302113ab0a@kernel.org/ >> >> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> >> --- >> arch/loongarch/include/asm/asm.h | 10 ++++++++++ >> arch/loongarch/kernel/entry.S | 1 + >> arch/loongarch/lib/memcpy.S | 3 +++ >> 3 files changed, 14 insertions(+) >> >> diff --git a/arch/loongarch/include/asm/asm.h b/arch/loongarch/include/asm/asm.h >> index 40eea6a..f591b32 100644 >> --- a/arch/loongarch/include/asm/asm.h >> +++ b/arch/loongarch/include/asm/asm.h >> @@ -188,4 +188,14 @@ >> #define PTRLOG 3 >> #endif >> >> +/* Annotate a function as being unsuitable for kprobes. */ >> +#ifdef CONFIG_KPROBES >> +#define _ASM_NOKPROBE(name) \ >> + .pushsection "_kprobe_blacklist", "aw"; \ >> + .quad name; \ >> + .popsection >> +#else >> +#define _ASM_NOKPROBE(name) >> +#endif >> + >> #endif /* __ASM_ASM_H */ >> diff --git a/arch/loongarch/kernel/entry.S b/arch/loongarch/kernel/entry.S >> index d53b631..55e23b1 100644 >> --- a/arch/loongarch/kernel/entry.S >> +++ b/arch/loongarch/kernel/entry.S >> @@ -67,6 +67,7 @@ SYM_FUNC_START(handle_syscall) >> >> RESTORE_ALL_AND_RET >> SYM_FUNC_END(handle_syscall) >> +_ASM_NOKPROBE(handle_syscall) >> >> SYM_CODE_START(ret_from_fork) >> bl schedule_tail # a0 = struct task_struct *prev >> diff --git a/arch/loongarch/lib/memcpy.S b/arch/loongarch/lib/memcpy.S >> index 7c07d59..3b7e1de 100644 >> --- a/arch/loongarch/lib/memcpy.S >> +++ b/arch/loongarch/lib/memcpy.S >> @@ -17,6 +17,7 @@ SYM_FUNC_START(memcpy) >> ALTERNATIVE "b __memcpy_generic", \ >> "b __memcpy_fast", CPU_FEATURE_UAL >> SYM_FUNC_END(memcpy) >> +_ASM_NOKPROBE(memcpy) >> >> EXPORT_SYMBOL(memcpy) >> >> @@ -41,6 +42,7 @@ SYM_FUNC_START(__memcpy_generic) >> 2: move a0, a3 >> jr ra >> SYM_FUNC_END(__memcpy_generic) >> +_ASM_NOKPROBE(__memcpy_generic) >> >> /* >> * void *__memcpy_fast(void *dst, const void *src, size_t n) >> @@ -93,3 +95,4 @@ SYM_FUNC_START(__memcpy_fast) >> 3: move a0, a3 >> jr ra >> SYM_FUNC_END(__memcpy_fast) >> +_ASM_NOKPROBE(__memcpy_fast) >> -- >> 2.1.0 >>
On 2023-01-18 12:23, Tiezhu Yang wrote: > > > On 01/18/2023 12:14 PM, Huacai Chen wrote: >> If memcpy should be blacklisted, then what about memset and memmove? > > According to the test results, there are no problems to probe > memset and memmove, so no need to blacklist them for now, > blacklist memcpy is because it may cause recursive exceptions, > there is a detailed discussion in the following link: > > https://lore.kernel.org/lkml/20230114143859.7ccc45c1c5d9ce302113ab0a@kernel.org/ > Hi, Tiezhu, I cannot reproduce the results when kprobe memcpy. Could you please give some details. Emm, I just replace "kernel_clone" with "memcpy" in kprobe_example.c. And for your call trace, handler_pre() pr_info() printk() _printk() vprintk() vprintk_store() memcpy() I think when we should skip this time kprobe which triggered in handler_{pre, post}. That means this time kprobe will not call handler_{pre, post} agian, and not cause recursion. I remember your codes had done this skip action. So, that's so strange if recursion in handler_{pre, post}. Thanks, Jinyang > > Thanks, > Tiezhu > >> >> Huacai >> >> On Wed, Jan 18, 2023 at 10:01 AM Tiezhu Yang <yangtiezhu@loongson.cn> >> wrote: >>> >>> Some assembler symbols are not kprobe safe, such as handle_syscall >>> (used as syscall exception handler), *memcpy* (may cause recursive >>> exceptions), they can not be instrumented, just blacklist them for >>> kprobing. >>> >>> Here is a related problem and discussion: >>> Link: >>> https://lore.kernel.org/lkml/20230114143859.7ccc45c1c5d9ce302113ab0a@kernel.org/ >>> >>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> >>> --- >>> arch/loongarch/include/asm/asm.h | 10 ++++++++++ >>> arch/loongarch/kernel/entry.S | 1 + >>> arch/loongarch/lib/memcpy.S | 3 +++ >>> 3 files changed, 14 insertions(+) >>> >>> diff --git a/arch/loongarch/include/asm/asm.h >>> b/arch/loongarch/include/asm/asm.h >>> index 40eea6a..f591b32 100644 >>> --- a/arch/loongarch/include/asm/asm.h >>> +++ b/arch/loongarch/include/asm/asm.h >>> @@ -188,4 +188,14 @@ >>> #define PTRLOG 3 >>> #endif >>> >>> +/* Annotate a function as being unsuitable for kprobes. */ >>> +#ifdef CONFIG_KPROBES >>> +#define _ASM_NOKPROBE(name) \ >>> + .pushsection "_kprobe_blacklist", "aw"; \ >>> + .quad name; \ >>> + .popsection >>> +#else >>> +#define _ASM_NOKPROBE(name) >>> +#endif >>> + >>> #endif /* __ASM_ASM_H */ >>> diff --git a/arch/loongarch/kernel/entry.S >>> b/arch/loongarch/kernel/entry.S >>> index d53b631..55e23b1 100644 >>> --- a/arch/loongarch/kernel/entry.S >>> +++ b/arch/loongarch/kernel/entry.S >>> @@ -67,6 +67,7 @@ SYM_FUNC_START(handle_syscall) >>> >>> RESTORE_ALL_AND_RET >>> SYM_FUNC_END(handle_syscall) >>> +_ASM_NOKPROBE(handle_syscall) >>> >>> SYM_CODE_START(ret_from_fork) >>> bl schedule_tail # a0 = struct task_struct *prev >>> diff --git a/arch/loongarch/lib/memcpy.S b/arch/loongarch/lib/memcpy.S >>> index 7c07d59..3b7e1de 100644 >>> --- a/arch/loongarch/lib/memcpy.S >>> +++ b/arch/loongarch/lib/memcpy.S >>> @@ -17,6 +17,7 @@ SYM_FUNC_START(memcpy) >>> ALTERNATIVE "b __memcpy_generic", \ >>> "b __memcpy_fast", CPU_FEATURE_UAL >>> SYM_FUNC_END(memcpy) >>> +_ASM_NOKPROBE(memcpy) >>> >>> EXPORT_SYMBOL(memcpy) >>> >>> @@ -41,6 +42,7 @@ SYM_FUNC_START(__memcpy_generic) >>> 2: move a0, a3 >>> jr ra >>> SYM_FUNC_END(__memcpy_generic) >>> +_ASM_NOKPROBE(__memcpy_generic) >>> >>> /* >>> * void *__memcpy_fast(void *dst, const void *src, size_t n) >>> @@ -93,3 +95,4 @@ SYM_FUNC_START(__memcpy_fast) >>> 3: move a0, a3 >>> jr ra >>> SYM_FUNC_END(__memcpy_fast) >>> +_ASM_NOKPROBE(__memcpy_fast) >>> -- >>> 2.1.0 >>> >
On 01/18/2023 02:05 PM, Jinyang He wrote: > > On 2023-01-18 12:23, Tiezhu Yang wrote: >> >> >> On 01/18/2023 12:14 PM, Huacai Chen wrote: >>> If memcpy should be blacklisted, then what about memset and memmove? >> >> According to the test results, there are no problems to probe >> memset and memmove, so no need to blacklist them for now, >> blacklist memcpy is because it may cause recursive exceptions, >> there is a detailed discussion in the following link: >> >> https://lore.kernel.org/lkml/20230114143859.7ccc45c1c5d9ce302113ab0a@kernel.org/ >> > > Hi, Tiezhu, > > I cannot reproduce the results when kprobe memcpy. Could you please give > some details. Emm, I just replace "kernel_clone" with "memcpy" in > kprobe_example.c. Please remove the related "_ASM_NOKPROBE(memcpy)" code in arch/loongarch/lib/memcpy.S, and then compile and update kernel, execute the following cmd after reboot, I can reproduce the hang problem easily (it will take a few minutes). modprobe kprobe_example symbol="memcpy" > > And for your call trace, > > handler_pre() > pr_info() > printk() > _printk() > vprintk() > vprintk_store() > memcpy() > > I think when we should skip this time kprobe which triggered in > handler_{pre, post}. That means this time kprobe will not call > handler_{pre, post} agian, and not cause recursion. I remember > your codes had done this skip action. So, that's so strange if > recursion in handler_{pre, post}. > > > Thanks, > > Jinyang > > >> >> Thanks, >> Tiezhu >> >>> >>> Huacai >>> >>> On Wed, Jan 18, 2023 at 10:01 AM Tiezhu Yang <yangtiezhu@loongson.cn> >>> wrote: >>>> >>>> Some assembler symbols are not kprobe safe, such as handle_syscall >>>> (used as syscall exception handler), *memcpy* (may cause recursive >>>> exceptions), they can not be instrumented, just blacklist them for >>>> kprobing. >>>> >>>> Here is a related problem and discussion: >>>> Link: >>>> https://lore.kernel.org/lkml/20230114143859.7ccc45c1c5d9ce302113ab0a@kernel.org/ >>>> >>>> >>>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> >>>> --- >>>> arch/loongarch/include/asm/asm.h | 10 ++++++++++ >>>> arch/loongarch/kernel/entry.S | 1 + >>>> arch/loongarch/lib/memcpy.S | 3 +++ >>>> 3 files changed, 14 insertions(+) >>>> >>>> diff --git a/arch/loongarch/include/asm/asm.h >>>> b/arch/loongarch/include/asm/asm.h >>>> index 40eea6a..f591b32 100644 >>>> --- a/arch/loongarch/include/asm/asm.h >>>> +++ b/arch/loongarch/include/asm/asm.h >>>> @@ -188,4 +188,14 @@ >>>> #define PTRLOG 3 >>>> #endif >>>> >>>> +/* Annotate a function as being unsuitable for kprobes. */ >>>> +#ifdef CONFIG_KPROBES >>>> +#define _ASM_NOKPROBE(name) \ >>>> + .pushsection "_kprobe_blacklist", "aw"; \ >>>> + .quad name; \ >>>> + .popsection >>>> +#else >>>> +#define _ASM_NOKPROBE(name) >>>> +#endif >>>> + >>>> #endif /* __ASM_ASM_H */ >>>> diff --git a/arch/loongarch/kernel/entry.S >>>> b/arch/loongarch/kernel/entry.S >>>> index d53b631..55e23b1 100644 >>>> --- a/arch/loongarch/kernel/entry.S >>>> +++ b/arch/loongarch/kernel/entry.S >>>> @@ -67,6 +67,7 @@ SYM_FUNC_START(handle_syscall) >>>> >>>> RESTORE_ALL_AND_RET >>>> SYM_FUNC_END(handle_syscall) >>>> +_ASM_NOKPROBE(handle_syscall) >>>> >>>> SYM_CODE_START(ret_from_fork) >>>> bl schedule_tail # a0 = struct task_struct *prev >>>> diff --git a/arch/loongarch/lib/memcpy.S b/arch/loongarch/lib/memcpy.S >>>> index 7c07d59..3b7e1de 100644 >>>> --- a/arch/loongarch/lib/memcpy.S >>>> +++ b/arch/loongarch/lib/memcpy.S >>>> @@ -17,6 +17,7 @@ SYM_FUNC_START(memcpy) >>>> ALTERNATIVE "b __memcpy_generic", \ >>>> "b __memcpy_fast", CPU_FEATURE_UAL >>>> SYM_FUNC_END(memcpy) >>>> +_ASM_NOKPROBE(memcpy) >>>> >>>> EXPORT_SYMBOL(memcpy) >>>> >>>> @@ -41,6 +42,7 @@ SYM_FUNC_START(__memcpy_generic) >>>> 2: move a0, a3 >>>> jr ra >>>> SYM_FUNC_END(__memcpy_generic) >>>> +_ASM_NOKPROBE(__memcpy_generic) >>>> >>>> /* >>>> * void *__memcpy_fast(void *dst, const void *src, size_t n) >>>> @@ -93,3 +95,4 @@ SYM_FUNC_START(__memcpy_fast) >>>> 3: move a0, a3 >>>> jr ra >>>> SYM_FUNC_END(__memcpy_fast) >>>> +_ASM_NOKPROBE(__memcpy_fast) >>>> -- >>>> 2.1.0 >>>> >>
On Wed, Jan 18, 2023 at 2:24 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: > > > > On 01/18/2023 02:05 PM, Jinyang He wrote: > > > > On 2023-01-18 12:23, Tiezhu Yang wrote: > >> > >> > >> On 01/18/2023 12:14 PM, Huacai Chen wrote: > >>> If memcpy should be blacklisted, then what about memset and memmove? > >> > >> According to the test results, there are no problems to probe > >> memset and memmove, so no need to blacklist them for now, > >> blacklist memcpy is because it may cause recursive exceptions, > >> there is a detailed discussion in the following link: > >> > >> https://lore.kernel.org/lkml/20230114143859.7ccc45c1c5d9ce302113ab0a@kernel.org/ > >> > > > > Hi, Tiezhu, > > > > I cannot reproduce the results when kprobe memcpy. Could you please give > > some details. Emm, I just replace "kernel_clone" with "memcpy" in > > kprobe_example.c. > > Please remove the related "_ASM_NOKPROBE(memcpy)" code in > arch/loongarch/lib/memcpy.S, and then compile and update kernel, > execute the following cmd after reboot, I can reproduce the hang > problem easily (it will take a few minutes). > > modprobe kprobe_example symbol="memcpy" Then, why is handle_syscall different from other exception handlers? Huacai > > > > > And for your call trace, > > > > handler_pre() > > pr_info() > > printk() > > _printk() > > vprintk() > > vprintk_store() > > memcpy() > > > > I think when we should skip this time kprobe which triggered in > > handler_{pre, post}. That means this time kprobe will not call > > handler_{pre, post} agian, and not cause recursion. I remember > > your codes had done this skip action. So, that's so strange if > > recursion in handler_{pre, post}. > > > > > > Thanks, > > > > Jinyang > > > > > >> > >> Thanks, > >> Tiezhu > >> > >>> > >>> Huacai > >>> > >>> On Wed, Jan 18, 2023 at 10:01 AM Tiezhu Yang <yangtiezhu@loongson.cn> > >>> wrote: > >>>> > >>>> Some assembler symbols are not kprobe safe, such as handle_syscall > >>>> (used as syscall exception handler), *memcpy* (may cause recursive > >>>> exceptions), they can not be instrumented, just blacklist them for > >>>> kprobing. > >>>> > >>>> Here is a related problem and discussion: > >>>> Link: > >>>> https://lore.kernel.org/lkml/20230114143859.7ccc45c1c5d9ce302113ab0a@kernel.org/ > >>>> > >>>> > >>>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> > >>>> --- > >>>> arch/loongarch/include/asm/asm.h | 10 ++++++++++ > >>>> arch/loongarch/kernel/entry.S | 1 + > >>>> arch/loongarch/lib/memcpy.S | 3 +++ > >>>> 3 files changed, 14 insertions(+) > >>>> > >>>> diff --git a/arch/loongarch/include/asm/asm.h > >>>> b/arch/loongarch/include/asm/asm.h > >>>> index 40eea6a..f591b32 100644 > >>>> --- a/arch/loongarch/include/asm/asm.h > >>>> +++ b/arch/loongarch/include/asm/asm.h > >>>> @@ -188,4 +188,14 @@ > >>>> #define PTRLOG 3 > >>>> #endif > >>>> > >>>> +/* Annotate a function as being unsuitable for kprobes. */ > >>>> +#ifdef CONFIG_KPROBES > >>>> +#define _ASM_NOKPROBE(name) \ > >>>> + .pushsection "_kprobe_blacklist", "aw"; \ > >>>> + .quad name; \ > >>>> + .popsection > >>>> +#else > >>>> +#define _ASM_NOKPROBE(name) > >>>> +#endif > >>>> + > >>>> #endif /* __ASM_ASM_H */ > >>>> diff --git a/arch/loongarch/kernel/entry.S > >>>> b/arch/loongarch/kernel/entry.S > >>>> index d53b631..55e23b1 100644 > >>>> --- a/arch/loongarch/kernel/entry.S > >>>> +++ b/arch/loongarch/kernel/entry.S > >>>> @@ -67,6 +67,7 @@ SYM_FUNC_START(handle_syscall) > >>>> > >>>> RESTORE_ALL_AND_RET > >>>> SYM_FUNC_END(handle_syscall) > >>>> +_ASM_NOKPROBE(handle_syscall) > >>>> > >>>> SYM_CODE_START(ret_from_fork) > >>>> bl schedule_tail # a0 = struct task_struct *prev > >>>> diff --git a/arch/loongarch/lib/memcpy.S b/arch/loongarch/lib/memcpy.S > >>>> index 7c07d59..3b7e1de 100644 > >>>> --- a/arch/loongarch/lib/memcpy.S > >>>> +++ b/arch/loongarch/lib/memcpy.S > >>>> @@ -17,6 +17,7 @@ SYM_FUNC_START(memcpy) > >>>> ALTERNATIVE "b __memcpy_generic", \ > >>>> "b __memcpy_fast", CPU_FEATURE_UAL > >>>> SYM_FUNC_END(memcpy) > >>>> +_ASM_NOKPROBE(memcpy) > >>>> > >>>> EXPORT_SYMBOL(memcpy) > >>>> > >>>> @@ -41,6 +42,7 @@ SYM_FUNC_START(__memcpy_generic) > >>>> 2: move a0, a3 > >>>> jr ra > >>>> SYM_FUNC_END(__memcpy_generic) > >>>> +_ASM_NOKPROBE(__memcpy_generic) > >>>> > >>>> /* > >>>> * void *__memcpy_fast(void *dst, const void *src, size_t n) > >>>> @@ -93,3 +95,4 @@ SYM_FUNC_START(__memcpy_fast) > >>>> 3: move a0, a3 > >>>> jr ra > >>>> SYM_FUNC_END(__memcpy_fast) > >>>> +_ASM_NOKPROBE(__memcpy_fast) > >>>> -- > >>>> 2.1.0 > >>>> > >> > >
On 2023-01-18 14:24, Tiezhu Yang wrote: > > > On 01/18/2023 02:05 PM, Jinyang He wrote: >> >> On 2023-01-18 12:23, Tiezhu Yang wrote: >>> >>> >>> On 01/18/2023 12:14 PM, Huacai Chen wrote: >>>> If memcpy should be blacklisted, then what about memset and memmove? >>> >>> According to the test results, there are no problems to probe >>> memset and memmove, so no need to blacklist them for now, >>> blacklist memcpy is because it may cause recursive exceptions, >>> there is a detailed discussion in the following link: >>> >>> https://lore.kernel.org/lkml/20230114143859.7ccc45c1c5d9ce302113ab0a@kernel.org/ >>> >>> >> >> Hi, Tiezhu, >> >> I cannot reproduce the results when kprobe memcpy. Could you please give >> some details. Emm, I just replace "kernel_clone" with "memcpy" in >> kprobe_example.c. > > Please remove the related "_ASM_NOKPROBE(memcpy)" code in > arch/loongarch/lib/memcpy.S, and then compile and update kernel, > execute the following cmd after reboot, I can reproduce the hang > problem easily (it will take a few minutes). > > modprobe kprobe_example symbol="memcpy" Okay, I can reproduce the hang, but sometimes quickly while sometimes slowly. I do not know why it happend. Can you explain how recursion happens? I means, can you explain why no need mark {vprintk_store, vprintk, ... } as it may also cause recursion. > >> >> And for your call trace, >> >> handler_pre() >> pr_info() >> printk() >> _printk() >> vprintk() >> vprintk_store() >> memcpy() >> >> I think when we should skip this time kprobe which triggered in >> handler_{pre, post}. That means this time kprobe will not call >> handler_{pre, post} agian, and not cause recursion. I remember >> your codes had done this skip action. So, that's so strange if >> recursion in handler_{pre, post}. >> >> >> Thanks, >> >> Jinyang >> >> >>> >>> Thanks, >>> Tiezhu >>> >>>> >>>> Huacai >>>> >>>> On Wed, Jan 18, 2023 at 10:01 AM Tiezhu Yang <yangtiezhu@loongson.cn> >>>> wrote: >>>>> >>>>> Some assembler symbols are not kprobe safe, such as handle_syscall >>>>> (used as syscall exception handler), *memcpy* (may cause recursive >>>>> exceptions), they can not be instrumented, just blacklist them for >>>>> kprobing. >>>>> >>>>> Here is a related problem and discussion: >>>>> Link: >>>>> https://lore.kernel.org/lkml/20230114143859.7ccc45c1c5d9ce302113ab0a@kernel.org/ >>>>> >>>>> >>>>> >>>>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> >>>>> --- >>>>> arch/loongarch/include/asm/asm.h | 10 ++++++++++ >>>>> arch/loongarch/kernel/entry.S | 1 + >>>>> arch/loongarch/lib/memcpy.S | 3 +++ >>>>> 3 files changed, 14 insertions(+) >>>>> >>>>> diff --git a/arch/loongarch/include/asm/asm.h >>>>> b/arch/loongarch/include/asm/asm.h >>>>> index 40eea6a..f591b32 100644 >>>>> --- a/arch/loongarch/include/asm/asm.h >>>>> +++ b/arch/loongarch/include/asm/asm.h >>>>> @@ -188,4 +188,14 @@ >>>>> #define PTRLOG 3 >>>>> #endif >>>>> >>>>> +/* Annotate a function as being unsuitable for kprobes. */ >>>>> +#ifdef CONFIG_KPROBES >>>>> +#define _ASM_NOKPROBE(name) \ >>>>> + .pushsection "_kprobe_blacklist", "aw"; \ >>>>> + .quad name; \ >>>>> + .popsection >>>>> +#else >>>>> +#define _ASM_NOKPROBE(name) >>>>> +#endif >>>>> + >>>>> #endif /* __ASM_ASM_H */ >>>>> diff --git a/arch/loongarch/kernel/entry.S >>>>> b/arch/loongarch/kernel/entry.S >>>>> index d53b631..55e23b1 100644 >>>>> --- a/arch/loongarch/kernel/entry.S >>>>> +++ b/arch/loongarch/kernel/entry.S >>>>> @@ -67,6 +67,7 @@ SYM_FUNC_START(handle_syscall) >>>>> >>>>> RESTORE_ALL_AND_RET >>>>> SYM_FUNC_END(handle_syscall) >>>>> +_ASM_NOKPROBE(handle_syscall) >>>>> >>>>> SYM_CODE_START(ret_from_fork) >>>>> bl schedule_tail # a0 = struct task_struct >>>>> *prev >>>>> diff --git a/arch/loongarch/lib/memcpy.S >>>>> b/arch/loongarch/lib/memcpy.S >>>>> index 7c07d59..3b7e1de 100644 >>>>> --- a/arch/loongarch/lib/memcpy.S >>>>> +++ b/arch/loongarch/lib/memcpy.S >>>>> @@ -17,6 +17,7 @@ SYM_FUNC_START(memcpy) >>>>> ALTERNATIVE "b __memcpy_generic", \ >>>>> "b __memcpy_fast", CPU_FEATURE_UAL >>>>> SYM_FUNC_END(memcpy) >>>>> +_ASM_NOKPROBE(memcpy) >>>>> >>>>> EXPORT_SYMBOL(memcpy) >>>>> >>>>> @@ -41,6 +42,7 @@ SYM_FUNC_START(__memcpy_generic) >>>>> 2: move a0, a3 >>>>> jr ra >>>>> SYM_FUNC_END(__memcpy_generic) >>>>> +_ASM_NOKPROBE(__memcpy_generic) >>>>> >>>>> /* >>>>> * void *__memcpy_fast(void *dst, const void *src, size_t n) >>>>> @@ -93,3 +95,4 @@ SYM_FUNC_START(__memcpy_fast) >>>>> 3: move a0, a3 >>>>> jr ra >>>>> SYM_FUNC_END(__memcpy_fast) >>>>> +_ASM_NOKPROBE(__memcpy_fast) >>>>> -- >>>>> 2.1.0 >>>>> >>>
On Wed, 18 Jan 2023 15:17:00 +0800 Huacai Chen <chenhuacai@kernel.org> wrote: > On Wed, Jan 18, 2023 at 2:24 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: > > > > > > > > On 01/18/2023 02:05 PM, Jinyang He wrote: > > > > > > On 2023-01-18 12:23, Tiezhu Yang wrote: > > >> > > >> > > >> On 01/18/2023 12:14 PM, Huacai Chen wrote: > > >>> If memcpy should be blacklisted, then what about memset and memmove? > > >> > > >> According to the test results, there are no problems to probe > > >> memset and memmove, so no need to blacklist them for now, > > >> blacklist memcpy is because it may cause recursive exceptions, > > >> there is a detailed discussion in the following link: > > >> > > >> https://lore.kernel.org/lkml/20230114143859.7ccc45c1c5d9ce302113ab0a@kernel.org/ > > >> > > > > > > Hi, Tiezhu, > > > > > > I cannot reproduce the results when kprobe memcpy. Could you please give > > > some details. Emm, I just replace "kernel_clone" with "memcpy" in > > > kprobe_example.c. > > > > Please remove the related "_ASM_NOKPROBE(memcpy)" code in > > arch/loongarch/lib/memcpy.S, and then compile and update kernel, > > execute the following cmd after reboot, I can reproduce the hang > > problem easily (it will take a few minutes). > > > > modprobe kprobe_example symbol="memcpy" > Then, why is handle_syscall different from other exception handlers? I need to check the loongarch implementation of handle_syscall() but I guess in that handler the register set is not completely set as kernel one. In that case, the software breakpoint handler may not possible to handle it correctly. So it is better to avoid probing such "border" function by kprobes. Thank you, > > Huacai > > > > > > > > And for your call trace, > > > > > > handler_pre() > > > pr_info() > > > printk() > > > _printk() > > > vprintk() > > > vprintk_store() > > > memcpy() > > > > > > I think when we should skip this time kprobe which triggered in > > > handler_{pre, post}. That means this time kprobe will not call > > > handler_{pre, post} agian, and not cause recursion. I remember > > > your codes had done this skip action. So, that's so strange if > > > recursion in handler_{pre, post}. > > > > > > > > > Thanks, > > > > > > Jinyang > > > > > > > > >> > > >> Thanks, > > >> Tiezhu > > >> > > >>> > > >>> Huacai > > >>> > > >>> On Wed, Jan 18, 2023 at 10:01 AM Tiezhu Yang <yangtiezhu@loongson.cn> > > >>> wrote: > > >>>> > > >>>> Some assembler symbols are not kprobe safe, such as handle_syscall > > >>>> (used as syscall exception handler), *memcpy* (may cause recursive > > >>>> exceptions), they can not be instrumented, just blacklist them for > > >>>> kprobing. > > >>>> > > >>>> Here is a related problem and discussion: > > >>>> Link: > > >>>> https://lore.kernel.org/lkml/20230114143859.7ccc45c1c5d9ce302113ab0a@kernel.org/ > > >>>> > > >>>> > > >>>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> > > >>>> --- > > >>>> arch/loongarch/include/asm/asm.h | 10 ++++++++++ > > >>>> arch/loongarch/kernel/entry.S | 1 + > > >>>> arch/loongarch/lib/memcpy.S | 3 +++ > > >>>> 3 files changed, 14 insertions(+) > > >>>> > > >>>> diff --git a/arch/loongarch/include/asm/asm.h > > >>>> b/arch/loongarch/include/asm/asm.h > > >>>> index 40eea6a..f591b32 100644 > > >>>> --- a/arch/loongarch/include/asm/asm.h > > >>>> +++ b/arch/loongarch/include/asm/asm.h > > >>>> @@ -188,4 +188,14 @@ > > >>>> #define PTRLOG 3 > > >>>> #endif > > >>>> > > >>>> +/* Annotate a function as being unsuitable for kprobes. */ > > >>>> +#ifdef CONFIG_KPROBES > > >>>> +#define _ASM_NOKPROBE(name) \ > > >>>> + .pushsection "_kprobe_blacklist", "aw"; \ > > >>>> + .quad name; \ > > >>>> + .popsection > > >>>> +#else > > >>>> +#define _ASM_NOKPROBE(name) > > >>>> +#endif > > >>>> + > > >>>> #endif /* __ASM_ASM_H */ > > >>>> diff --git a/arch/loongarch/kernel/entry.S > > >>>> b/arch/loongarch/kernel/entry.S > > >>>> index d53b631..55e23b1 100644 > > >>>> --- a/arch/loongarch/kernel/entry.S > > >>>> +++ b/arch/loongarch/kernel/entry.S > > >>>> @@ -67,6 +67,7 @@ SYM_FUNC_START(handle_syscall) > > >>>> > > >>>> RESTORE_ALL_AND_RET > > >>>> SYM_FUNC_END(handle_syscall) > > >>>> +_ASM_NOKPROBE(handle_syscall) > > >>>> > > >>>> SYM_CODE_START(ret_from_fork) > > >>>> bl schedule_tail # a0 = struct task_struct *prev > > >>>> diff --git a/arch/loongarch/lib/memcpy.S b/arch/loongarch/lib/memcpy.S > > >>>> index 7c07d59..3b7e1de 100644 > > >>>> --- a/arch/loongarch/lib/memcpy.S > > >>>> +++ b/arch/loongarch/lib/memcpy.S > > >>>> @@ -17,6 +17,7 @@ SYM_FUNC_START(memcpy) > > >>>> ALTERNATIVE "b __memcpy_generic", \ > > >>>> "b __memcpy_fast", CPU_FEATURE_UAL > > >>>> SYM_FUNC_END(memcpy) > > >>>> +_ASM_NOKPROBE(memcpy) > > >>>> > > >>>> EXPORT_SYMBOL(memcpy) > > >>>> > > >>>> @@ -41,6 +42,7 @@ SYM_FUNC_START(__memcpy_generic) > > >>>> 2: move a0, a3 > > >>>> jr ra > > >>>> SYM_FUNC_END(__memcpy_generic) > > >>>> +_ASM_NOKPROBE(__memcpy_generic) > > >>>> > > >>>> /* > > >>>> * void *__memcpy_fast(void *dst, const void *src, size_t n) > > >>>> @@ -93,3 +95,4 @@ SYM_FUNC_START(__memcpy_fast) > > >>>> 3: move a0, a3 > > >>>> jr ra > > >>>> SYM_FUNC_END(__memcpy_fast) > > >>>> +_ASM_NOKPROBE(__memcpy_fast) > > >>>> -- > > >>>> 2.1.0 > > >>>> > > >> > > > >
On Thu, Jan 19, 2023 at 11:32 PM Masami Hiramatsu <mhiramat@kernel.org> wrote: > > On Wed, 18 Jan 2023 15:17:00 +0800 > Huacai Chen <chenhuacai@kernel.org> wrote: > > > On Wed, Jan 18, 2023 at 2:24 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: > > > > > > > > > > > > On 01/18/2023 02:05 PM, Jinyang He wrote: > > > > > > > > On 2023-01-18 12:23, Tiezhu Yang wrote: > > > >> > > > >> > > > >> On 01/18/2023 12:14 PM, Huacai Chen wrote: > > > >>> If memcpy should be blacklisted, then what about memset and memmove? > > > >> > > > >> According to the test results, there are no problems to probe > > > >> memset and memmove, so no need to blacklist them for now, > > > >> blacklist memcpy is because it may cause recursive exceptions, > > > >> there is a detailed discussion in the following link: > > > >> > > > >> https://lore.kernel.org/lkml/20230114143859.7ccc45c1c5d9ce302113ab0a@kernel.org/ > > > >> > > > > > > > > Hi, Tiezhu, > > > > > > > > I cannot reproduce the results when kprobe memcpy. Could you please give > > > > some details. Emm, I just replace "kernel_clone" with "memcpy" in > > > > kprobe_example.c. > > > > > > Please remove the related "_ASM_NOKPROBE(memcpy)" code in > > > arch/loongarch/lib/memcpy.S, and then compile and update kernel, > > > execute the following cmd after reboot, I can reproduce the hang > > > problem easily (it will take a few minutes). > > > > > > modprobe kprobe_example symbol="memcpy" > > Then, why is handle_syscall different from other exception handlers? > > I need to check the loongarch implementation of handle_syscall() but > I guess in that handler the register set is not completely set as > kernel one. In that case, the software breakpoint handler may not > possible to handle it correctly. So it is better to avoid probing such > "border" function by kprobes. Seems reasonable, handle_syscall() indeed doesn't save all registers. But for memcpy(), I still think memmove() and memset() may have the same problem. Huacai > > Thank you, > > > > > Huacai > > > > > > > > > > > And for your call trace, > > > > > > > > handler_pre() > > > > pr_info() > > > > printk() > > > > _printk() > > > > vprintk() > > > > vprintk_store() > > > > memcpy() > > > > > > > > I think when we should skip this time kprobe which triggered in > > > > handler_{pre, post}. That means this time kprobe will not call > > > > handler_{pre, post} agian, and not cause recursion. I remember > > > > your codes had done this skip action. So, that's so strange if > > > > recursion in handler_{pre, post}. > > > > > > > > > > > > Thanks, > > > > > > > > Jinyang > > > > > > > > > > > >> > > > >> Thanks, > > > >> Tiezhu > > > >> > > > >>> > > > >>> Huacai > > > >>> > > > >>> On Wed, Jan 18, 2023 at 10:01 AM Tiezhu Yang <yangtiezhu@loongson.cn> > > > >>> wrote: > > > >>>> > > > >>>> Some assembler symbols are not kprobe safe, such as handle_syscall > > > >>>> (used as syscall exception handler), *memcpy* (may cause recursive > > > >>>> exceptions), they can not be instrumented, just blacklist them for > > > >>>> kprobing. > > > >>>> > > > >>>> Here is a related problem and discussion: > > > >>>> Link: > > > >>>> https://lore.kernel.org/lkml/20230114143859.7ccc45c1c5d9ce302113ab0a@kernel.org/ > > > >>>> > > > >>>> > > > >>>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> > > > >>>> --- > > > >>>> arch/loongarch/include/asm/asm.h | 10 ++++++++++ > > > >>>> arch/loongarch/kernel/entry.S | 1 + > > > >>>> arch/loongarch/lib/memcpy.S | 3 +++ > > > >>>> 3 files changed, 14 insertions(+) > > > >>>> > > > >>>> diff --git a/arch/loongarch/include/asm/asm.h > > > >>>> b/arch/loongarch/include/asm/asm.h > > > >>>> index 40eea6a..f591b32 100644 > > > >>>> --- a/arch/loongarch/include/asm/asm.h > > > >>>> +++ b/arch/loongarch/include/asm/asm.h > > > >>>> @@ -188,4 +188,14 @@ > > > >>>> #define PTRLOG 3 > > > >>>> #endif > > > >>>> > > > >>>> +/* Annotate a function as being unsuitable for kprobes. */ > > > >>>> +#ifdef CONFIG_KPROBES > > > >>>> +#define _ASM_NOKPROBE(name) \ > > > >>>> + .pushsection "_kprobe_blacklist", "aw"; \ > > > >>>> + .quad name; \ > > > >>>> + .popsection > > > >>>> +#else > > > >>>> +#define _ASM_NOKPROBE(name) > > > >>>> +#endif > > > >>>> + > > > >>>> #endif /* __ASM_ASM_H */ > > > >>>> diff --git a/arch/loongarch/kernel/entry.S > > > >>>> b/arch/loongarch/kernel/entry.S > > > >>>> index d53b631..55e23b1 100644 > > > >>>> --- a/arch/loongarch/kernel/entry.S > > > >>>> +++ b/arch/loongarch/kernel/entry.S > > > >>>> @@ -67,6 +67,7 @@ SYM_FUNC_START(handle_syscall) > > > >>>> > > > >>>> RESTORE_ALL_AND_RET > > > >>>> SYM_FUNC_END(handle_syscall) > > > >>>> +_ASM_NOKPROBE(handle_syscall) > > > >>>> > > > >>>> SYM_CODE_START(ret_from_fork) > > > >>>> bl schedule_tail # a0 = struct task_struct *prev > > > >>>> diff --git a/arch/loongarch/lib/memcpy.S b/arch/loongarch/lib/memcpy.S > > > >>>> index 7c07d59..3b7e1de 100644 > > > >>>> --- a/arch/loongarch/lib/memcpy.S > > > >>>> +++ b/arch/loongarch/lib/memcpy.S > > > >>>> @@ -17,6 +17,7 @@ SYM_FUNC_START(memcpy) > > > >>>> ALTERNATIVE "b __memcpy_generic", \ > > > >>>> "b __memcpy_fast", CPU_FEATURE_UAL > > > >>>> SYM_FUNC_END(memcpy) > > > >>>> +_ASM_NOKPROBE(memcpy) > > > >>>> > > > >>>> EXPORT_SYMBOL(memcpy) > > > >>>> > > > >>>> @@ -41,6 +42,7 @@ SYM_FUNC_START(__memcpy_generic) > > > >>>> 2: move a0, a3 > > > >>>> jr ra > > > >>>> SYM_FUNC_END(__memcpy_generic) > > > >>>> +_ASM_NOKPROBE(__memcpy_generic) > > > >>>> > > > >>>> /* > > > >>>> * void *__memcpy_fast(void *dst, const void *src, size_t n) > > > >>>> @@ -93,3 +95,4 @@ SYM_FUNC_START(__memcpy_fast) > > > >>>> 3: move a0, a3 > > > >>>> jr ra > > > >>>> SYM_FUNC_END(__memcpy_fast) > > > >>>> +_ASM_NOKPROBE(__memcpy_fast) > > > >>>> -- > > > >>>> 2.1.0 > > > >>>> > > > >> > > > > > > > > > -- > Masami Hiramatsu (Google) <mhiramat@kernel.org>
On Fri, 20 Jan 2023 21:23:18 +0800 Huacai Chen <chenhuacai@kernel.org> wrote: > On Thu, Jan 19, 2023 at 11:32 PM Masami Hiramatsu <mhiramat@kernel.org> wrote: > > > > On Wed, 18 Jan 2023 15:17:00 +0800 > > Huacai Chen <chenhuacai@kernel.org> wrote: > > > > > On Wed, Jan 18, 2023 at 2:24 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: > > > > > > > > > > > > > > > > On 01/18/2023 02:05 PM, Jinyang He wrote: > > > > > > > > > > On 2023-01-18 12:23, Tiezhu Yang wrote: > > > > >> > > > > >> > > > > >> On 01/18/2023 12:14 PM, Huacai Chen wrote: > > > > >>> If memcpy should be blacklisted, then what about memset and memmove? > > > > >> > > > > >> According to the test results, there are no problems to probe > > > > >> memset and memmove, so no need to blacklist them for now, > > > > >> blacklist memcpy is because it may cause recursive exceptions, > > > > >> there is a detailed discussion in the following link: > > > > >> > > > > >> https://lore.kernel.org/lkml/20230114143859.7ccc45c1c5d9ce302113ab0a@kernel.org/ > > > > >> > > > > > > > > > > Hi, Tiezhu, > > > > > > > > > > I cannot reproduce the results when kprobe memcpy. Could you please give > > > > > some details. Emm, I just replace "kernel_clone" with "memcpy" in > > > > > kprobe_example.c. > > > > > > > > Please remove the related "_ASM_NOKPROBE(memcpy)" code in > > > > arch/loongarch/lib/memcpy.S, and then compile and update kernel, > > > > execute the following cmd after reboot, I can reproduce the hang > > > > problem easily (it will take a few minutes). > > > > > > > > modprobe kprobe_example symbol="memcpy" > > > Then, why is handle_syscall different from other exception handlers? > > > > I need to check the loongarch implementation of handle_syscall() but > > I guess in that handler the register set is not completely set as > > kernel one. In that case, the software breakpoint handler may not > > possible to handle it correctly. So it is better to avoid probing such > > "border" function by kprobes. > Seems reasonable, handle_syscall() indeed doesn't save all registers. > But for memcpy(), I still think memmove() and memset() may have the > same problem. I agree with that. Those fundamental functions can be used from some debug macros in the software breakpoint code in the future (or already?) Maybe you would better to check it with enabling some more (intrusive) debug features. Thank you, > > Huacai > > > > Thank you, > > > > > > > > Huacai > > > > > > > > > > > > > > And for your call trace, > > > > > > > > > > handler_pre() > > > > > pr_info() > > > > > printk() > > > > > _printk() > > > > > vprintk() > > > > > vprintk_store() > > > > > memcpy() > > > > > > > > > > I think when we should skip this time kprobe which triggered in > > > > > handler_{pre, post}. That means this time kprobe will not call > > > > > handler_{pre, post} agian, and not cause recursion. I remember > > > > > your codes had done this skip action. So, that's so strange if > > > > > recursion in handler_{pre, post}. > > > > > > > > > > > > > > > Thanks, > > > > > > > > > > Jinyang > > > > > > > > > > > > > > >> > > > > >> Thanks, > > > > >> Tiezhu > > > > >> > > > > >>> > > > > >>> Huacai > > > > >>> > > > > >>> On Wed, Jan 18, 2023 at 10:01 AM Tiezhu Yang <yangtiezhu@loongson.cn> > > > > >>> wrote: > > > > >>>> > > > > >>>> Some assembler symbols are not kprobe safe, such as handle_syscall > > > > >>>> (used as syscall exception handler), *memcpy* (may cause recursive > > > > >>>> exceptions), they can not be instrumented, just blacklist them for > > > > >>>> kprobing. > > > > >>>> > > > > >>>> Here is a related problem and discussion: > > > > >>>> Link: > > > > >>>> https://lore.kernel.org/lkml/20230114143859.7ccc45c1c5d9ce302113ab0a@kernel.org/ > > > > >>>> > > > > >>>> > > > > >>>> Signed-off-by: Tiezhu Yang <yangtiezhu@loongson.cn> > > > > >>>> --- > > > > >>>> arch/loongarch/include/asm/asm.h | 10 ++++++++++ > > > > >>>> arch/loongarch/kernel/entry.S | 1 + > > > > >>>> arch/loongarch/lib/memcpy.S | 3 +++ > > > > >>>> 3 files changed, 14 insertions(+) > > > > >>>> > > > > >>>> diff --git a/arch/loongarch/include/asm/asm.h > > > > >>>> b/arch/loongarch/include/asm/asm.h > > > > >>>> index 40eea6a..f591b32 100644 > > > > >>>> --- a/arch/loongarch/include/asm/asm.h > > > > >>>> +++ b/arch/loongarch/include/asm/asm.h > > > > >>>> @@ -188,4 +188,14 @@ > > > > >>>> #define PTRLOG 3 > > > > >>>> #endif > > > > >>>> > > > > >>>> +/* Annotate a function as being unsuitable for kprobes. */ > > > > >>>> +#ifdef CONFIG_KPROBES > > > > >>>> +#define _ASM_NOKPROBE(name) \ > > > > >>>> + .pushsection "_kprobe_blacklist", "aw"; \ > > > > >>>> + .quad name; \ > > > > >>>> + .popsection > > > > >>>> +#else > > > > >>>> +#define _ASM_NOKPROBE(name) > > > > >>>> +#endif > > > > >>>> + > > > > >>>> #endif /* __ASM_ASM_H */ > > > > >>>> diff --git a/arch/loongarch/kernel/entry.S > > > > >>>> b/arch/loongarch/kernel/entry.S > > > > >>>> index d53b631..55e23b1 100644 > > > > >>>> --- a/arch/loongarch/kernel/entry.S > > > > >>>> +++ b/arch/loongarch/kernel/entry.S > > > > >>>> @@ -67,6 +67,7 @@ SYM_FUNC_START(handle_syscall) > > > > >>>> > > > > >>>> RESTORE_ALL_AND_RET > > > > >>>> SYM_FUNC_END(handle_syscall) > > > > >>>> +_ASM_NOKPROBE(handle_syscall) > > > > >>>> > > > > >>>> SYM_CODE_START(ret_from_fork) > > > > >>>> bl schedule_tail # a0 = struct task_struct *prev > > > > >>>> diff --git a/arch/loongarch/lib/memcpy.S b/arch/loongarch/lib/memcpy.S > > > > >>>> index 7c07d59..3b7e1de 100644 > > > > >>>> --- a/arch/loongarch/lib/memcpy.S > > > > >>>> +++ b/arch/loongarch/lib/memcpy.S > > > > >>>> @@ -17,6 +17,7 @@ SYM_FUNC_START(memcpy) > > > > >>>> ALTERNATIVE "b __memcpy_generic", \ > > > > >>>> "b __memcpy_fast", CPU_FEATURE_UAL > > > > >>>> SYM_FUNC_END(memcpy) > > > > >>>> +_ASM_NOKPROBE(memcpy) > > > > >>>> > > > > >>>> EXPORT_SYMBOL(memcpy) > > > > >>>> > > > > >>>> @@ -41,6 +42,7 @@ SYM_FUNC_START(__memcpy_generic) > > > > >>>> 2: move a0, a3 > > > > >>>> jr ra > > > > >>>> SYM_FUNC_END(__memcpy_generic) > > > > >>>> +_ASM_NOKPROBE(__memcpy_generic) > > > > >>>> > > > > >>>> /* > > > > >>>> * void *__memcpy_fast(void *dst, const void *src, size_t n) > > > > >>>> @@ -93,3 +95,4 @@ SYM_FUNC_START(__memcpy_fast) > > > > >>>> 3: move a0, a3 > > > > >>>> jr ra > > > > >>>> SYM_FUNC_END(__memcpy_fast) > > > > >>>> +_ASM_NOKPROBE(__memcpy_fast) > > > > >>>> -- > > > > >>>> 2.1.0 > > > > >>>> > > > > >> > > > > > > > > > > > > > > -- > > Masami Hiramatsu (Google) <mhiramat@kernel.org>
diff --git a/arch/loongarch/include/asm/asm.h b/arch/loongarch/include/asm/asm.h index 40eea6a..f591b32 100644 --- a/arch/loongarch/include/asm/asm.h +++ b/arch/loongarch/include/asm/asm.h @@ -188,4 +188,14 @@ #define PTRLOG 3 #endif +/* Annotate a function as being unsuitable for kprobes. */ +#ifdef CONFIG_KPROBES +#define _ASM_NOKPROBE(name) \ + .pushsection "_kprobe_blacklist", "aw"; \ + .quad name; \ + .popsection +#else +#define _ASM_NOKPROBE(name) +#endif + #endif /* __ASM_ASM_H */ diff --git a/arch/loongarch/kernel/entry.S b/arch/loongarch/kernel/entry.S index d53b631..55e23b1 100644 --- a/arch/loongarch/kernel/entry.S +++ b/arch/loongarch/kernel/entry.S @@ -67,6 +67,7 @@ SYM_FUNC_START(handle_syscall) RESTORE_ALL_AND_RET SYM_FUNC_END(handle_syscall) +_ASM_NOKPROBE(handle_syscall) SYM_CODE_START(ret_from_fork) bl schedule_tail # a0 = struct task_struct *prev diff --git a/arch/loongarch/lib/memcpy.S b/arch/loongarch/lib/memcpy.S index 7c07d59..3b7e1de 100644 --- a/arch/loongarch/lib/memcpy.S +++ b/arch/loongarch/lib/memcpy.S @@ -17,6 +17,7 @@ SYM_FUNC_START(memcpy) ALTERNATIVE "b __memcpy_generic", \ "b __memcpy_fast", CPU_FEATURE_UAL SYM_FUNC_END(memcpy) +_ASM_NOKPROBE(memcpy) EXPORT_SYMBOL(memcpy) @@ -41,6 +42,7 @@ SYM_FUNC_START(__memcpy_generic) 2: move a0, a3 jr ra SYM_FUNC_END(__memcpy_generic) +_ASM_NOKPROBE(__memcpy_generic) /* * void *__memcpy_fast(void *dst, const void *src, size_t n) @@ -93,3 +95,4 @@ SYM_FUNC_START(__memcpy_fast) 3: move a0, a3 jr ra SYM_FUNC_END(__memcpy_fast) +_ASM_NOKPROBE(__memcpy_fast)