Received: by 2002:a05:6358:d09b:b0:dc:cd0c:909e with SMTP id jc27csp143062rwb; Mon, 28 Nov 2022 18:17:32 -0800 (PST) X-Google-Smtp-Source: AA0mqf6n3j44zC31pQtlKKrxIzhyXOXW6voEf+agmEQ3HlbBfmwmbjQl2Ig/maDIKn46JpixgPuO X-Received: by 2002:a17:90a:4496:b0:20a:f638:3c9f with SMTP id t22-20020a17090a449600b0020af6383c9fmr64077676pjg.38.1669688252147; Mon, 28 Nov 2022 18:17:32 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1669688252; cv=none; d=google.com; s=arc-20160816; b=bLSlmmTxpo/+DCoVf+4EGHoePhrOr0GqdT0esz72ArP8RKdID34ndkxIzFcchKuHxW Y4vu83UeDue2hxrY6YZ61+KLSUMlMBfjO8al4L9Y5zQ1cPVMa9Qtkvo35jDoq6Mebryy 1OOOVbmMp8V1FQ62X1F24VFAPik4c0XSNtJGKLPkKveUVo3qfX9yvQ91QMzgmslcZMys OZnUkYjGA6UBrlh8s8kGGJ4Cjg722QRju5MuOfFt4U+4o3AYEDOx0qdFZ6m1k31l2XU5 Jv9nJvp5tiVXdnQiYBOtoEYs1wKT/OLOZ93Y//JYShx4fi/KDjIUhpHPkDXQ4yWGJHzl pZyg== 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=sL6/lZiQQ0pvu6J5XgLbLxh3VmmNJBL39BgrYTyYO7U=; b=Q5p6rYBlExzmGSJCi+xXo1axO7sqZUSB4MEafAhyzPY+/MC93l3B6OOhGg590OQ/J2 4HGA/A1NTyeNT7zn8CNTL8HOvYlxkqFNqmNPIWlpjrrthQSQ1gidzZl0bAHsztOBRf5l llymxmp8L0YPURwaF78/YC3PEH7sYv6EU4Y4ZjW7a1utGvPLHaLskmvqYZ5dW8ny0MZD XY3t6x2b48W8kPtP0TJcByE+CJnMcb+tv9nGmSBvYJGv5ps3MF2PA/+Z51FFQp0pdaVR 7qm16AYRwlLhKnSIeCLhbIUcD4u//ikR1dHl/Y29h/oa/wq6SqtLPaKzsuovUjDYKV+R 4iaQ== 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 d9-20020a056a00244900b0056bbdb48fcdsi13883474pfj.118.2022.11.28.18.17.22; Mon, 28 Nov 2022 18:17:32 -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 S235024AbiK2CDL (ORCPT + 82 others); Mon, 28 Nov 2022 21:03:11 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:50256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S235012AbiK2CDI (ORCPT ); Mon, 28 Nov 2022 21:03:08 -0500 Received: from loongson.cn (mail.loongson.cn [114.242.206.163]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id DE7E910B7C for ; Mon, 28 Nov 2022 18:03:04 -0800 (PST) Received: from loongson.cn (unknown [113.200.148.30]) by gateway (Coremail) with SMTP id _____8Dx_+tWaIVjKeIBAA--.4495S3; Tue, 29 Nov 2022 10:03:03 +0800 (CST) Received: from linux.localdomain (unknown [113.200.148.30]) by localhost.localdomain (Coremail) with SMTP id AQAAf8AxPuBUaIVjPdsdAA--.10463S2; Tue, 29 Nov 2022 10:03:00 +0800 (CST) From: Tiezhu Yang To: Huacai Chen , WANG Xuerui , Masami Hiramatsu Cc: loongarch@lists.linux.dev, linux-kernel@vger.kernel.org Subject: [PATCH v5 0/4] Add kprobe and kretprobe support for LoongArch Date: Tue, 29 Nov 2022 10:02:50 +0800 Message-Id: <1669687374-16432-1-git-send-email-yangtiezhu@loongson.cn> X-Mailer: git-send-email 2.1.0 X-CM-TRANSID: AQAAf8AxPuBUaIVjPdsdAA--.10463S2 X-CM-SenderInfo: p1dqw3xlh2x3gn0dqz5rrqw2lrqou0/ X-Coremail-Antispam: 1Uk129KBjvJXoWxJr4xtw4UKr43Ar4xAw4xZwb_yoW8ArWxpF 9rZwn8Kr4rGrn3Jr9xt3WUur1ftw18C3y2ga17try8C3W7XryUArs3KrZxXa4rKwsIqr1S qr1rX3yYgFyxJa7anT9S1TB71UUUUUJqnTZGkaVYY2UrUUUUj1kv1TuYvTs0mT0YCTnIWj qI5I8CrVACY4xI64kE6c02F40Ex7xfYxn0WfASr-VFAUDa7-sFnT9fnUUIcSsGvfJTRUUU b3AYFVCjjxCrM7AC8VAFwI0_Jr0_Gr1l1xkIjI8I6I8E6xAIw20EY4v20xvaj40_Wr0E3s 1l1IIY67AEw4v_Jr0_Jr4l8cAvFVAK0II2c7xJM28CjxkF64kEwVA0rcxSw2x7M28EF7xv wVC0I7IYx2IY67AKxVW7JVWDJwA2z4x0Y4vE2Ix0cI8IcVCY1x0267AKxVWxJVW8Jr1l84 ACjcxK6I8E87Iv67AKxVW8Jr0_Cr1UM28EF7xvwVC2z280aVCY1x0267AKxVW8Jr0_Cr1U M2kKe7AKxVWUXVWUAwAS0I0E0xvYzxvE52x082IY62kv0487Mc804VCY07AIYIkI8VC2zV CFFI0UMc02F40EFcxC0VAKzVAqx4xG6I80ewAv7VC0I7IYx2IY67AKxVWUXVWUAwAv7VC2 z280aVAFwI0_Jr0_Gr1lOx8S6xCaFVCjc4AY6r1j6r4UM4x0Y48IcxkI7VAKI48JMxAIw2 8IcxkI7VAKI48JMxC20s026xCaFVCjc4AY6r1j6r4UMxCIbckI1I0E14v26r1Y6r17MI8I 3I0E5I8CrVAFwI0_Jr0_Jr4lx2IqxVCjr7xvwVAFwI0_JrI_JrWlx4CE17CEb7AF67AKxV WUAVWUtwCIc40Y0x0EwIxGrwCI42IY6xIIjxv20xvE14v26r1j6r1xMIIF0xvE2Ix0cI8I cVCY1x0267AKxVWUJVW8JwCI42IY6xAIw20EY4v20xvaj40_Jr0_JF4lIxAIcVC2z280aV AFwI0_Jr0_Gr1lIxAIcVC2z280aVCY1x0267AKxVWUJVW8JbIYCTnIWIevJa73UjIFyTuY vjxU74lkDUUUU 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 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 | 22 ++ arch/loongarch/include/asm/kprobes.h | 65 ++++++ arch/loongarch/include/asm/ptrace.h | 1 + arch/loongarch/kernel/Makefile | 2 + arch/loongarch/kernel/inst.c | 123 ++++++++++ arch/loongarch/kernel/kprobes.c | 350 +++++++++++++++++++++++++++++ arch/loongarch/kernel/kprobes_trampoline.S | 96 ++++++++ arch/loongarch/kernel/traps.c | 6 +- arch/loongarch/mm/fault.c | 4 + samples/kprobes/kprobe_example.c | 8 + 11 files changed, 675 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