Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp2434266rwb; Fri, 9 Dec 2022 01:58:15 -0800 (PST) X-Google-Smtp-Source: AA0mqf7grMpEp1vPc4MMAnERRyhSuPwnR3lbRUhCxM9n4HDAh9J+dZmxZH7QDLy4VeXoQmF4f7TS X-Received: by 2002:a17:906:51d6:b0:7c0:c312:acaa with SMTP id v22-20020a17090651d600b007c0c312acaamr4208569ejk.49.1670579895667; Fri, 09 Dec 2022 01:58:15 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1670579895; cv=none; d=google.com; s=arc-20160816; b=EOPcRBP4RIXEo6peWREKa86ICUGBlsm4o99awMmTYwl+zjJVHQ2UGexmh61XoIZ1kG epyUQl8GafTtZRQ2oRhUP9/QDpzAqAxv5R0LSlPrzNJwnOrFyUYf0Mkau39szU7AkqP2 LuvFbcHFotVkCHzI7Mdw2++9uoOj9A66LdkuCxjNxSWIAuwRMHghpS492fSuPNV53BYO HKiqHi4MVP1kluliQ4PLKBo1FJb85a2ZdtbhIxnQUE2dpQhnad3pGWgktA82TfJbNEbi yiDXWLZ/Hhv3D2mXU9b4I3txiLNWKDVxvtcTf1ZtrHsuRDlEYOv4JOoIVWvL+mG/HQSr OgPQ== 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id e20-20020a17090658d400b007adf9d2fa0fsi874002ejs.947.2022.12.09.01.57.58; Fri, 09 Dec 2022 01:58:15 -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 + 73 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 ); 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 ; 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 To: Huacai Chen , WANG Xuerui , Masami Hiramatsu 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: X-Mailing-List: linux-kernel@vger.kernel.org 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