Message ID | 1670575981-14389-1-git-send-email-yangtiezhu@loongson.cn |
---|---|
Headers |
Return-Path: <linux-kernel-owner@vger.kernel.org> Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:f944:0:0:0:0:0 with SMTP id q4csp659008wrr; Fri, 9 Dec 2022 01:00:42 -0800 (PST) X-Google-Smtp-Source: AA0mqf5+0lfH3meMJWdFyJsEAfxWGp95SVWbKkSWWIEVDIcca/GMZiXE/bbFa9omShbqVUhw+NRt X-Received: by 2002:a05:6a20:6f90:b0:a3:9ca0:b982 with SMTP id gv16-20020a056a206f9000b000a39ca0b982mr6780390pzb.26.1670576441761; Fri, 09 Dec 2022 01:00:41 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670576441; cv=none; d=google.com; s=arc-20160816; b=M1qICnu7EOs3IGw29lS52E2LaL/f/dh/6xOAdKRIXeHvuZMqBQdtfXqwjSrR2rT94t cMlJsognZaloCMR3LsT1eqjoYCNffp3w70Ujk+LT0JOURb/tuWef39M5WBjrVYGnGEf3 ju8P+Hj03xEhaRABYsJRz1HxV1BZQNIUg8eb0g875ijJvvykI3KQ8NrIESs5eidzCC4p i60xt/mhfKboJBauFsDrSCU+fA7AprAr0nWil5ligJbVGPjYs2RS3EuihYfTxOWlg6M4 fERTZh0VFPiFGZM7m179myD50cH5b4+pFkysPynr1vUDJrzkhDIpCroHWeFqN4xDjwZY rt+A== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:message-id:date:subject:cc:to:from; bh=IlUloWDB/GiVY/KwwDC/vffMboC41ZCWiYg44s4g39U=; b=q4p91Ys8+L7hGi9LNsXZys00cHrtyvb9YApCEpnP8uC3aZLsgn5tllIvraPcMZ0w4q YKZeWQY3FTcMFOURrwnWg9R+jc9e1K35qclxg7rjfjvlurmaM2nXApwEvNTSiL/xNT5t tbNm8UM+hT1jJqTF8YZMHMav1Kp3WuPv77njCxI9ozjLNRBp5C9YUf87l89Mka80RTtb zVjTv3OHvivLciCzt+6IepAWWqyjWOEgWJIfJVJJ59/Vx6aWwzV2kMHPKZH7NuogmFdm nwWqQpg1f/9p/fQr8I5+cuKEhWliTe+H17BCkGtcuv8YT86tIe3KXCY63H1jtva1fhdD SgXw== 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 n4-20020a170902f60400b00186a2d376afsi43396plg.273.2022.12.09.01.00.27; Fri, 09 Dec 2022 01:00:41 -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 S229886AbiLIIxN (ORCPT <rfc822;sophiezhao968@gmail.com> + 99 others); Fri, 9 Dec 2022 03:53:13 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54764 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229890AbiLIIxJ (ORCPT <rfc822;linux-kernel@vger.kernel.org>); Fri, 9 Dec 2022 03:53:09 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 9ECFD31EE6 for <linux-kernel@vger.kernel.org>; Fri, 9 Dec 2022 00:53:06 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8Bxnutw95JjEGAEAA--.10359S3; Fri, 09 Dec 2022 16:53:05 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8BxV1dt95Jj7xUpAA--.16661S2; Fri, 09 Dec 2022 16:53:02 +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 v10 0/4] Add kprobe and kretprobe support for LoongArch Date: Fri, 9 Dec 2022 16:52:57 +0800 Message-Id: <1670575981-14389-1-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf8BxV1dt95Jj7xUpAA--.16661S2 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjvJXoWxJF4furW8Xr1rJry3KrW3Wrg_yoW5XFyDpF 9rAwn5Kr4rWrn3Zr9xta4Uur1Sqw4kG3y7W3W7JrWrZ3W7ZryUAr4xKrZxXFy8Gws0qr1S qr1fXrWagFyfGa7anT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b38YFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_JrI_Jryl8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVWUCVW8JwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVW8JVWxJwA2z4 x0Y4vEx4A2jsIE14v26F4UJVW0owA2z4x0Y4vEx4A2jsIEc7CjxVAFwI0_Cr1j6rxdM2kK e7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zVCFFI 0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUXVWUAwAv7VC2z280 aVAFwI0_Gr0_Cr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw28Icx kI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v26r1Y6r17MI8I3I0E 5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxVWUAV WUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8IcVCY 1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aVAFwI 0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuYvjxU 4oGQDUUUU 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?1751726363014421923?= X-GMAIL-MSGID: =?utf-8?q?1751726363014421923?= |
Series |
Add kprobe and kretprobe support for LoongArch
|
|
Message
Tiezhu Yang
Dec. 9, 2022, 8:52 a.m. UTC
v10: -- Remove sign_extend() based on the latest code -- Rename insns_are_not_supported() to insns_not_supported() -- Rename insns_are_not_simulated() to insns_not_simulated() -- Set KPROBE_HIT_SSDONE if cur->post_handler is not NULL -- Enable preemption for KPROBE_REENTER in kprobe_fault_handler() v9: -- Rename sign_extended() to sign_extend() -- Modify kprobe_fault_handler() to handle all of kprobe_status v8: -- Put "regs->csr_prmd &= ~CSR_PRMD_PIE;" ahead to save one line -- Add code comment of preempt_disable() -- Put kprobe_page_fault() in __do_page_fault() -- Modify the check condition of break insn in kprobe_breakpoint_handler() v7: -- Remove stop_machine_cpuslocked() related code v6: -- Add a new patch to redefine larch_insn_patch_text() with stop_machine_cpuslocked() -- Modify kprobe_breakpoint_handler() to consider the original insn is break and return the correct value -- Modify do_bp() to refresh bcode when original insn is break v5: -- Rebase on the latest code -- Use stop_machine_cpuslocked() to modify insn to avoid CPU race v4: -- Remove kprobe_exceptions_notify() in kprobes.c -- Call kprobe_breakpoint_handler() and kprobe_singlestep_handler() in do_bp() v3: -- Rebase on the latest code -- Check the alignment of PC in simu_branch() and simu_pc() -- Add ibar in flush_insn_slot() -- Rename kprobe_{pre,post}_handler() to {post_}kprobe_handler -- Add preempt_disable() and preempt_enable_no_resched() -- Remove r0 save/restore and do some minor changes in kprobes_trampoline.S -- Do not enable CONFIG_KPROBES by default v2: -- Split simu_branch() and simu_pc() into a single patch -- Call kprobe_page_fault() in do_page_fault() -- Add kprobes_trampoline.S for kretprobe Tiezhu Yang (4): LoongArch: Simulate branch and PC instructions LoongArch: Add kprobe support LoongArch: Add kretprobe support samples/kprobes: Add LoongArch support arch/loongarch/Kconfig | 2 + arch/loongarch/include/asm/inst.h | 20 ++ arch/loongarch/include/asm/kprobes.h | 59 +++++ arch/loongarch/include/asm/ptrace.h | 1 + arch/loongarch/kernel/Makefile | 2 + arch/loongarch/kernel/inst.c | 123 ++++++++++ arch/loongarch/kernel/kprobes.c | 364 +++++++++++++++++++++++++++++ arch/loongarch/kernel/kprobes_trampoline.S | 96 ++++++++ arch/loongarch/kernel/traps.c | 13 +- arch/loongarch/mm/fault.c | 3 + samples/kprobes/kprobe_example.c | 8 + 11 files changed, 687 insertions(+), 4 deletions(-) create mode 100644 arch/loongarch/include/asm/kprobes.h create mode 100644 arch/loongarch/kernel/kprobes.c create mode 100644 arch/loongarch/kernel/kprobes_trampoline.S
Comments
Hi, Masami, This series looks good to me now, but I'm not familiar with kprobes. So, if you have any comments, please let me know. And Jeff, As we all know, you are an expert in this domain, so could you please help me to test this series? If there are no objections, I plan to merge this series in a few days. But since the next merge window will be open soon, if there are any problems, I will revert the patches to wait for the next cycle. Thanks, Huacai On Fri, Dec 9, 2022 at 4:53 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: > > v10: > -- Remove sign_extend() based on the latest code > -- Rename insns_are_not_supported() to insns_not_supported() > -- Rename insns_are_not_simulated() to insns_not_simulated() > -- Set KPROBE_HIT_SSDONE if cur->post_handler is not NULL > -- Enable preemption for KPROBE_REENTER in kprobe_fault_handler() > > v9: > -- Rename sign_extended() to sign_extend() > -- Modify kprobe_fault_handler() to handle all of kprobe_status > > v8: > -- Put "regs->csr_prmd &= ~CSR_PRMD_PIE;" ahead to save one line > -- Add code comment of preempt_disable() > -- Put kprobe_page_fault() in __do_page_fault() > -- Modify the check condition of break insn in kprobe_breakpoint_handler() > > v7: > -- Remove stop_machine_cpuslocked() related code > > v6: > -- Add a new patch to redefine larch_insn_patch_text() with > stop_machine_cpuslocked() > -- Modify kprobe_breakpoint_handler() to consider the original > insn is break and return the correct value > -- Modify do_bp() to refresh bcode when original insn is break > > v5: > -- Rebase on the latest code > -- Use stop_machine_cpuslocked() to modify insn to avoid CPU race > > v4: > -- Remove kprobe_exceptions_notify() in kprobes.c > -- Call kprobe_breakpoint_handler() and kprobe_singlestep_handler() > in do_bp() > > v3: > -- Rebase on the latest code > -- Check the alignment of PC in simu_branch() and simu_pc() > -- Add ibar in flush_insn_slot() > -- Rename kprobe_{pre,post}_handler() to {post_}kprobe_handler > -- Add preempt_disable() and preempt_enable_no_resched() > -- Remove r0 save/restore and do some minor changes > in kprobes_trampoline.S > -- Do not enable CONFIG_KPROBES by default > > v2: > -- Split simu_branch() and simu_pc() into a single patch > -- Call kprobe_page_fault() in do_page_fault() > -- Add kprobes_trampoline.S for kretprobe > > Tiezhu Yang (4): > LoongArch: Simulate branch and PC instructions > LoongArch: Add kprobe support > LoongArch: Add kretprobe support > samples/kprobes: Add LoongArch support > > arch/loongarch/Kconfig | 2 + > arch/loongarch/include/asm/inst.h | 20 ++ > arch/loongarch/include/asm/kprobes.h | 59 +++++ > arch/loongarch/include/asm/ptrace.h | 1 + > arch/loongarch/kernel/Makefile | 2 + > arch/loongarch/kernel/inst.c | 123 ++++++++++ > arch/loongarch/kernel/kprobes.c | 364 +++++++++++++++++++++++++++++ > arch/loongarch/kernel/kprobes_trampoline.S | 96 ++++++++ > arch/loongarch/kernel/traps.c | 13 +- > arch/loongarch/mm/fault.c | 3 + > samples/kprobes/kprobe_example.c | 8 + > 11 files changed, 687 insertions(+), 4 deletions(-) > create mode 100644 arch/loongarch/include/asm/kprobes.h > create mode 100644 arch/loongarch/kernel/kprobes.c > create mode 100644 arch/loongarch/kernel/kprobes_trampoline.S > > -- > 2.1.0 >
On 2022/12/9 18:01, Huacai Chen wrote: > Hi, Masami, > > This series looks good to me now, but I'm not familiar with kprobes. > So, if you have any comments, please let me know. > > And Jeff, > > As we all know, you are an expert in this domain, so could you please > help me to test this series? > > If there are no objections, I plan to merge this series in a few days. > But since the next merge window will be open soon, if there are any > problems, I will revert the patches to wait for the next cycle. Sorry for jumping in so late, but due to the imminence of the merge window, and Linus having *specifically* asked for readiness of all 6.2 material upfront due to holidays, IMHO it could be more prudent to wait one more cycle. Especially considering some other people's code probably already made the respective maintainers more cautious due to the compile warnings, and hurried fixes to some other similarly hurried commits...
On Fri, Dec 9, 2022 at 6:01 PM Huacai Chen <chenhuacai@kernel.org> wrote: > > Hi, Masami, > > This series looks good to me now, but I'm not familiar with kprobes. > So, if you have any comments, please let me know. > > And Jeff, > > As we all know, you are an expert in this domain, so could you please > help me to test this series? > > If there are no objections, I plan to merge this series in a few days. > But since the next merge window will be open soon, if there are any > problems, I will revert the patches to wait for the next cycle. I can't use the kprobe function normally now, tested the function from the branch: https://github.com/loongson/linux/commits/loongarch-next steps: 1. Try to probe __memset_fast() [root@loongarch ]# cat /proc/kallsyms | grep __memset_fast 90000000012c75f0 T __memset_fast ./samples/kprobes/kprobe_example.c static char symbol[KSYM_NAME_LEN] = "__memset_fast"; 2. Loading the kprobe_example.ko [root@loongarch mnt]# insmod ./kprobe_example.ko *** The system will keep hanging *** dmesg-messages: gef➤ lx-dmesg [ 12.348047] handler_pre: <__memset_fast> p->addr = 0x(____ptrval____), era = 0x90000000012c75f0, estat = 0xc0000 [ 12.348512] handler_post: <__memset_fast> p->addr = 0x(____ptrval____), estat = 0xc0000 [ 12.348525] handler_post: <__memset_fast> p->addr = 0x(____ptrval____), estat = 0xc0000 [ 12.349248] handler_pre: <__memset_fast> p->addr = 0x(____ptrval____), era = 0x90000000012c75f0, estat = 0xc0000 [ 12.349259] handler_post: <__memset_fast> p->addr = 0x(____ptrval____), estat = 0xc0000 call trace: gef➤ bt #0 0x90000000012f45f8 in queued_spin_lock_slowpath (lock=0x9000000001cc0018 <die_lock>, val=0x1) at kernel/locking/qspinlock.c:383 #1 0x9000000000223b2c in die (str=str@entry=0x90000000017e3488 "Break instruction in kernel code", regs=regs@entry=0x900000010fd735f0) at arch/loongarch/kernel/traps.c:240 #2 0x90000000012e3968 in die_if_kernel (regs=<optimized out>, str=<optimized out>) at ./arch/loongarch/include/asm/ptrace.h:131 #3 do_bp (regs=0x900000010fd735f0) at arch/loongarch/kernel/traps.c:485 #4 0x9000000001cb1924 in exception_handlers () Backtrace stopped: frame did not save the PC > Thanks, > Huacai > > On Fri, Dec 9, 2022 at 4:53 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: > > > > v10: > > -- Remove sign_extend() based on the latest code > > -- Rename insns_are_not_supported() to insns_not_supported() > > -- Rename insns_are_not_simulated() to insns_not_simulated() > > -- Set KPROBE_HIT_SSDONE if cur->post_handler is not NULL > > -- Enable preemption for KPROBE_REENTER in kprobe_fault_handler() > > > > v9: > > -- Rename sign_extended() to sign_extend() > > -- Modify kprobe_fault_handler() to handle all of kprobe_status > > > > v8: > > -- Put "regs->csr_prmd &= ~CSR_PRMD_PIE;" ahead to save one line > > -- Add code comment of preempt_disable() > > -- Put kprobe_page_fault() in __do_page_fault() > > -- Modify the check condition of break insn in kprobe_breakpoint_handler() > > > > v7: > > -- Remove stop_machine_cpuslocked() related code > > > > v6: > > -- Add a new patch to redefine larch_insn_patch_text() with > > stop_machine_cpuslocked() > > -- Modify kprobe_breakpoint_handler() to consider the original > > insn is break and return the correct value > > -- Modify do_bp() to refresh bcode when original insn is break > > > > v5: > > -- Rebase on the latest code > > -- Use stop_machine_cpuslocked() to modify insn to avoid CPU race > > > > v4: > > -- Remove kprobe_exceptions_notify() in kprobes.c > > -- Call kprobe_breakpoint_handler() and kprobe_singlestep_handler() > > in do_bp() > > > > v3: > > -- Rebase on the latest code > > -- Check the alignment of PC in simu_branch() and simu_pc() > > -- Add ibar in flush_insn_slot() > > -- Rename kprobe_{pre,post}_handler() to {post_}kprobe_handler > > -- Add preempt_disable() and preempt_enable_no_resched() > > -- Remove r0 save/restore and do some minor changes > > in kprobes_trampoline.S > > -- Do not enable CONFIG_KPROBES by default > > > > v2: > > -- Split simu_branch() and simu_pc() into a single patch > > -- Call kprobe_page_fault() in do_page_fault() > > -- Add kprobes_trampoline.S for kretprobe > > > > Tiezhu Yang (4): > > LoongArch: Simulate branch and PC instructions > > LoongArch: Add kprobe support > > LoongArch: Add kretprobe support > > samples/kprobes: Add LoongArch support > > > > arch/loongarch/Kconfig | 2 + > > arch/loongarch/include/asm/inst.h | 20 ++ > > arch/loongarch/include/asm/kprobes.h | 59 +++++ > > arch/loongarch/include/asm/ptrace.h | 1 + > > arch/loongarch/kernel/Makefile | 2 + > > arch/loongarch/kernel/inst.c | 123 ++++++++++ > > arch/loongarch/kernel/kprobes.c | 364 +++++++++++++++++++++++++++++ > > arch/loongarch/kernel/kprobes_trampoline.S | 96 ++++++++ > > arch/loongarch/kernel/traps.c | 13 +- > > arch/loongarch/mm/fault.c | 3 + > > samples/kprobes/kprobe_example.c | 8 + > > 11 files changed, 687 insertions(+), 4 deletions(-) > > create mode 100644 arch/loongarch/include/asm/kprobes.h > > create mode 100644 arch/loongarch/kernel/kprobes.c > > create mode 100644 arch/loongarch/kernel/kprobes_trampoline.S > > > > -- > > 2.1.0 > >
Hi, Tiezhu: I tested this patchset from BPF side, failed with EINVAL: $ cat /sys/kernel/tracing/error_log [ 262.299093] trace_kprobe: error: Failed to register probe event Command: p:kprobes/libbpf_4609_inet_bind_0x0_0 inet_bind+0x0 ^ -- Hengqi On 2022/12/9 16:52, Tiezhu Yang wrote: > v10: > -- Remove sign_extend() based on the latest code > -- Rename insns_are_not_supported() to insns_not_supported() > -- Rename insns_are_not_simulated() to insns_not_simulated() > -- Set KPROBE_HIT_SSDONE if cur->post_handler is not NULL > -- Enable preemption for KPROBE_REENTER in kprobe_fault_handler() > > v9: > -- Rename sign_extended() to sign_extend() > -- Modify kprobe_fault_handler() to handle all of kprobe_status > > v8: > -- Put "regs->csr_prmd &= ~CSR_PRMD_PIE;" ahead to save one line > -- Add code comment of preempt_disable() > -- Put kprobe_page_fault() in __do_page_fault() > -- Modify the check condition of break insn in kprobe_breakpoint_handler() > > v7: > -- Remove stop_machine_cpuslocked() related code > > v6: > -- Add a new patch to redefine larch_insn_patch_text() with > stop_machine_cpuslocked() > -- Modify kprobe_breakpoint_handler() to consider the original > insn is break and return the correct value > -- Modify do_bp() to refresh bcode when original insn is break > > v5: > -- Rebase on the latest code > -- Use stop_machine_cpuslocked() to modify insn to avoid CPU race > > v4: > -- Remove kprobe_exceptions_notify() in kprobes.c > -- Call kprobe_breakpoint_handler() and kprobe_singlestep_handler() > in do_bp() > > v3: > -- Rebase on the latest code > -- Check the alignment of PC in simu_branch() and simu_pc() > -- Add ibar in flush_insn_slot() > -- Rename kprobe_{pre,post}_handler() to {post_}kprobe_handler > -- Add preempt_disable() and preempt_enable_no_resched() > -- Remove r0 save/restore and do some minor changes > in kprobes_trampoline.S > -- Do not enable CONFIG_KPROBES by default > > v2: > -- Split simu_branch() and simu_pc() into a single patch > -- Call kprobe_page_fault() in do_page_fault() > -- Add kprobes_trampoline.S for kretprobe > > Tiezhu Yang (4): > LoongArch: Simulate branch and PC instructions > LoongArch: Add kprobe support > LoongArch: Add kretprobe support > samples/kprobes: Add LoongArch support > > arch/loongarch/Kconfig | 2 + > arch/loongarch/include/asm/inst.h | 20 ++ > arch/loongarch/include/asm/kprobes.h | 59 +++++ > arch/loongarch/include/asm/ptrace.h | 1 + > arch/loongarch/kernel/Makefile | 2 + > arch/loongarch/kernel/inst.c | 123 ++++++++++ > arch/loongarch/kernel/kprobes.c | 364 +++++++++++++++++++++++++++++ > arch/loongarch/kernel/kprobes_trampoline.S | 96 ++++++++ > arch/loongarch/kernel/traps.c | 13 +- > arch/loongarch/mm/fault.c | 3 + > samples/kprobes/kprobe_example.c | 8 + > 11 files changed, 687 insertions(+), 4 deletions(-) > create mode 100644 arch/loongarch/include/asm/kprobes.h > create mode 100644 arch/loongarch/kernel/kprobes.c > create mode 100644 arch/loongarch/kernel/kprobes_trampoline.S >
Hi, Hengqi On 2022/12/12 下午4:41, Hengqi Chen wrote: > Hi, Tiezhu: > > I tested this patchset from BPF side, failed with EINVAL: > > $ cat /sys/kernel/tracing/error_log > [ 262.299093] trace_kprobe: error: Failed to register probe event > Command: p:kprobes/libbpf_4609_inet_bind_0x0_0 inet_bind+0x0 > This is because KPROBE_ON_FTRACE is not yet supported. Trace Event cannot be used now. We will support it soon, if you want to test it by install kprobe_example.ko as jeff did. Thanks -Qing ^ > -- > Hengqi > > On 2022/12/9 16:52, Tiezhu Yang wrote: >> v10: >> -- Remove sign_extend() based on the latest code >> -- Rename insns_are_not_supported() to insns_not_supported() >> -- Rename insns_are_not_simulated() to insns_not_simulated() >> -- Set KPROBE_HIT_SSDONE if cur->post_handler is not NULL >> -- Enable preemption for KPROBE_REENTER in kprobe_fault_handler() >> >> v9: >> -- Rename sign_extended() to sign_extend() >> -- Modify kprobe_fault_handler() to handle all of kprobe_status >> >> v8: >> -- Put "regs->csr_prmd &= ~CSR_PRMD_PIE;" ahead to save one line >> -- Add code comment of preempt_disable() >> -- Put kprobe_page_fault() in __do_page_fault() >> -- Modify the check condition of break insn in kprobe_breakpoint_handler() >> >> v7: >> -- Remove stop_machine_cpuslocked() related code >> >> v6: >> -- Add a new patch to redefine larch_insn_patch_text() with >> stop_machine_cpuslocked() >> -- Modify kprobe_breakpoint_handler() to consider the original >> insn is break and return the correct value >> -- Modify do_bp() to refresh bcode when original insn is break >> >> v5: >> -- Rebase on the latest code >> -- Use stop_machine_cpuslocked() to modify insn to avoid CPU race >> >> v4: >> -- Remove kprobe_exceptions_notify() in kprobes.c >> -- Call kprobe_breakpoint_handler() and kprobe_singlestep_handler() >> in do_bp() >> >> v3: >> -- Rebase on the latest code >> -- Check the alignment of PC in simu_branch() and simu_pc() >> -- Add ibar in flush_insn_slot() >> -- Rename kprobe_{pre,post}_handler() to {post_}kprobe_handler >> -- Add preempt_disable() and preempt_enable_no_resched() >> -- Remove r0 save/restore and do some minor changes >> in kprobes_trampoline.S >> -- Do not enable CONFIG_KPROBES by default >> >> v2: >> -- Split simu_branch() and simu_pc() into a single patch >> -- Call kprobe_page_fault() in do_page_fault() >> -- Add kprobes_trampoline.S for kretprobe >> >> Tiezhu Yang (4): >> LoongArch: Simulate branch and PC instructions >> LoongArch: Add kprobe support >> LoongArch: Add kretprobe support >> samples/kprobes: Add LoongArch support >> >> arch/loongarch/Kconfig | 2 + >> arch/loongarch/include/asm/inst.h | 20 ++ >> arch/loongarch/include/asm/kprobes.h | 59 +++++ >> arch/loongarch/include/asm/ptrace.h | 1 + >> arch/loongarch/kernel/Makefile | 2 + >> arch/loongarch/kernel/inst.c | 123 ++++++++++ >> arch/loongarch/kernel/kprobes.c | 364 +++++++++++++++++++++++++++++ >> arch/loongarch/kernel/kprobes_trampoline.S | 96 ++++++++ >> arch/loongarch/kernel/traps.c | 13 +- >> arch/loongarch/mm/fault.c | 3 + >> samples/kprobes/kprobe_example.c | 8 + >> 11 files changed, 687 insertions(+), 4 deletions(-) >> create mode 100644 arch/loongarch/include/asm/kprobes.h >> create mode 100644 arch/loongarch/kernel/kprobes.c >> create mode 100644 arch/loongarch/kernel/kprobes_trampoline.S >>
On Fri, 9 Dec 2022 18:01:44 +0800 Huacai Chen <chenhuacai@kernel.org> wrote: > Hi, Masami, > > This series looks good to me now, but I'm not familiar with kprobes. > So, if you have any comments, please let me know. Sorry I missed this series. Let me add some comments. BTW, I don't have any board to run the loongarch, so I'll make comments just about style issues. Thanks, > > And Jeff, > > As we all know, you are an expert in this domain, so could you please > help me to test this series? > > If there are no objections, I plan to merge this series in a few days. > But since the next merge window will be open soon, if there are any > problems, I will revert the patches to wait for the next cycle. > > Thanks, > Huacai > > On Fri, Dec 9, 2022 at 4:53 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: > > > > v10: > > -- Remove sign_extend() based on the latest code > > -- Rename insns_are_not_supported() to insns_not_supported() > > -- Rename insns_are_not_simulated() to insns_not_simulated() > > -- Set KPROBE_HIT_SSDONE if cur->post_handler is not NULL > > -- Enable preemption for KPROBE_REENTER in kprobe_fault_handler() > > > > v9: > > -- Rename sign_extended() to sign_extend() > > -- Modify kprobe_fault_handler() to handle all of kprobe_status > > > > v8: > > -- Put "regs->csr_prmd &= ~CSR_PRMD_PIE;" ahead to save one line > > -- Add code comment of preempt_disable() > > -- Put kprobe_page_fault() in __do_page_fault() > > -- Modify the check condition of break insn in kprobe_breakpoint_handler() > > > > v7: > > -- Remove stop_machine_cpuslocked() related code > > > > v6: > > -- Add a new patch to redefine larch_insn_patch_text() with > > stop_machine_cpuslocked() > > -- Modify kprobe_breakpoint_handler() to consider the original > > insn is break and return the correct value > > -- Modify do_bp() to refresh bcode when original insn is break > > > > v5: > > -- Rebase on the latest code > > -- Use stop_machine_cpuslocked() to modify insn to avoid CPU race > > > > v4: > > -- Remove kprobe_exceptions_notify() in kprobes.c > > -- Call kprobe_breakpoint_handler() and kprobe_singlestep_handler() > > in do_bp() > > > > v3: > > -- Rebase on the latest code > > -- Check the alignment of PC in simu_branch() and simu_pc() > > -- Add ibar in flush_insn_slot() > > -- Rename kprobe_{pre,post}_handler() to {post_}kprobe_handler > > -- Add preempt_disable() and preempt_enable_no_resched() > > -- Remove r0 save/restore and do some minor changes > > in kprobes_trampoline.S > > -- Do not enable CONFIG_KPROBES by default > > > > v2: > > -- Split simu_branch() and simu_pc() into a single patch > > -- Call kprobe_page_fault() in do_page_fault() > > -- Add kprobes_trampoline.S for kretprobe > > > > Tiezhu Yang (4): > > LoongArch: Simulate branch and PC instructions > > LoongArch: Add kprobe support > > LoongArch: Add kretprobe support > > samples/kprobes: Add LoongArch support > > > > arch/loongarch/Kconfig | 2 + > > arch/loongarch/include/asm/inst.h | 20 ++ > > arch/loongarch/include/asm/kprobes.h | 59 +++++ > > arch/loongarch/include/asm/ptrace.h | 1 + > > arch/loongarch/kernel/Makefile | 2 + > > arch/loongarch/kernel/inst.c | 123 ++++++++++ > > arch/loongarch/kernel/kprobes.c | 364 +++++++++++++++++++++++++++++ > > arch/loongarch/kernel/kprobes_trampoline.S | 96 ++++++++ > > arch/loongarch/kernel/traps.c | 13 +- > > arch/loongarch/mm/fault.c | 3 + > > samples/kprobes/kprobe_example.c | 8 + > > 11 files changed, 687 insertions(+), 4 deletions(-) > > create mode 100644 arch/loongarch/include/asm/kprobes.h > > create mode 100644 arch/loongarch/kernel/kprobes.c > > create mode 100644 arch/loongarch/kernel/kprobes_trampoline.S > > > > -- > > 2.1.0 > >
Hi, Masami, On Tue, Dec 13, 2022 at 11:10 AM Masami Hiramatsu <mhiramat@kernel.org> wrote: > > On Fri, 9 Dec 2022 18:01:44 +0800 > Huacai Chen <chenhuacai@kernel.org> wrote: > > > Hi, Masami, > > > > This series looks good to me now, but I'm not familiar with kprobes. > > So, if you have any comments, please let me know. > > Sorry I missed this series. Let me add some comments. > BTW, I don't have any board to run the loongarch, so I'll make > comments just about style issues. You needn't say sorry, and you can use qemu to run loongarch if needed. Huacai > > Thanks, > > > > > And Jeff, > > > > As we all know, you are an expert in this domain, so could you please > > help me to test this series? > > > > If there are no objections, I plan to merge this series in a few days. > > But since the next merge window will be open soon, if there are any > > problems, I will revert the patches to wait for the next cycle. > > > > Thanks, > > Huacai > > > > On Fri, Dec 9, 2022 at 4:53 PM Tiezhu Yang <yangtiezhu@loongson.cn> wrote: > > > > > > v10: > > > -- Remove sign_extend() based on the latest code > > > -- Rename insns_are_not_supported() to insns_not_supported() > > > -- Rename insns_are_not_simulated() to insns_not_simulated() > > > -- Set KPROBE_HIT_SSDONE if cur->post_handler is not NULL > > > -- Enable preemption for KPROBE_REENTER in kprobe_fault_handler() > > > > > > v9: > > > -- Rename sign_extended() to sign_extend() > > > -- Modify kprobe_fault_handler() to handle all of kprobe_status > > > > > > v8: > > > -- Put "regs->csr_prmd &= ~CSR_PRMD_PIE;" ahead to save one line > > > -- Add code comment of preempt_disable() > > > -- Put kprobe_page_fault() in __do_page_fault() > > > -- Modify the check condition of break insn in kprobe_breakpoint_handler() > > > > > > v7: > > > -- Remove stop_machine_cpuslocked() related code > > > > > > v6: > > > -- Add a new patch to redefine larch_insn_patch_text() with > > > stop_machine_cpuslocked() > > > -- Modify kprobe_breakpoint_handler() to consider the original > > > insn is break and return the correct value > > > -- Modify do_bp() to refresh bcode when original insn is break > > > > > > v5: > > > -- Rebase on the latest code > > > -- Use stop_machine_cpuslocked() to modify insn to avoid CPU race > > > > > > v4: > > > -- Remove kprobe_exceptions_notify() in kprobes.c > > > -- Call kprobe_breakpoint_handler() and kprobe_singlestep_handler() > > > in do_bp() > > > > > > v3: > > > -- Rebase on the latest code > > > -- Check the alignment of PC in simu_branch() and simu_pc() > > > -- Add ibar in flush_insn_slot() > > > -- Rename kprobe_{pre,post}_handler() to {post_}kprobe_handler > > > -- Add preempt_disable() and preempt_enable_no_resched() > > > -- Remove r0 save/restore and do some minor changes > > > in kprobes_trampoline.S > > > -- Do not enable CONFIG_KPROBES by default > > > > > > v2: > > > -- Split simu_branch() and simu_pc() into a single patch > > > -- Call kprobe_page_fault() in do_page_fault() > > > -- Add kprobes_trampoline.S for kretprobe > > > > > > Tiezhu Yang (4): > > > LoongArch: Simulate branch and PC instructions > > > LoongArch: Add kprobe support > > > LoongArch: Add kretprobe support > > > samples/kprobes: Add LoongArch support > > > > > > arch/loongarch/Kconfig | 2 + > > > arch/loongarch/include/asm/inst.h | 20 ++ > > > arch/loongarch/include/asm/kprobes.h | 59 +++++ > > > arch/loongarch/include/asm/ptrace.h | 1 + > > > arch/loongarch/kernel/Makefile | 2 + > > > arch/loongarch/kernel/inst.c | 123 ++++++++++ > > > arch/loongarch/kernel/kprobes.c | 364 +++++++++++++++++++++++++++++ > > > arch/loongarch/kernel/kprobes_trampoline.S | 96 ++++++++ > > > arch/loongarch/kernel/traps.c | 13 +- > > > arch/loongarch/mm/fault.c | 3 + > > > samples/kprobes/kprobe_example.c | 8 + > > > 11 files changed, 687 insertions(+), 4 deletions(-) > > > create mode 100644 arch/loongarch/include/asm/kprobes.h > > > create mode 100644 arch/loongarch/kernel/kprobes.c > > > create mode 100644 arch/loongarch/kernel/kprobes_trampoline.S > > > > > > -- > > > 2.1.0 > > > > > > -- > Masami Hiramatsu (Google) <mhiramat@kernel.org>