From patchwork Tue Aug 10 05:53:28 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "liuqi (BA)" X-Patchwork-Id: 12428429 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-10.9 required=3.0 tests=BAYES_00,DATE_IN_PAST_03_06, DKIMWL_WL_HIGH,DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=unavailable autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 1F92BC4338F for ; Tue, 10 Aug 2021 09:20:56 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id DB87F60E76 for ; Tue, 10 Aug 2021 09:20:55 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org DB87F60E76 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=huawei.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Message-ID:Date:Subject:CC :To:From:Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From: Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References: List-Owner; bh=H15jjIHCNGGqj8rAm86Fl5030vW1KR9vYZtzTYA4/d0=; b=Ijg7Cau2cifnIo SiAWeotiDCEJP8Pb/vy6eF/Q1gNIuBzIS1Ar17fnTRymxyrPpX26mgDUmuXBBnvfbVBb3lm62UtrS IIA7TXnXKzsHWA2zpdPR9O7VBbEsv156PZOJ3HhVFGItyCsAVCfew+7wTEEKhzg9PIxQNOdaClerg daFz11K2+JLDkKqxFAD5P1TNY3KmaxeQ7JVWFglJFcRyIN+ruzd/pyXmTbSnwbcJrTl0nWKpNXJ7w IHA/cV+7V+7mPMIsNViH2cWyKoCBZ8/khta4Pn3KCwDoYbEsZGH4CfgQQQ7VEymRqCI18+l1lAQin 3Y1aZk5H8DPTk3ouxILg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mDNtg-003Ena-CM; Tue, 10 Aug 2021 09:18:08 +0000 Received: from szxga01-in.huawei.com ([45.249.212.187]) by bombadil.infradead.org with esmtps (Exim 4.94.2 #2 (Red Hat Linux)) id 1mDNtb-003Elh-Gy for linux-arm-kernel@lists.infradead.org; Tue, 10 Aug 2021 09:18:05 +0000 Received: from dggemv711-chm.china.huawei.com (unknown [172.30.72.56]) by szxga01-in.huawei.com (SkyGuard) with ESMTP id 4GkS233Gmwzb0G0; Tue, 10 Aug 2021 17:14:19 +0800 (CST) Received: from dggema757-chm.china.huawei.com (10.1.198.199) by dggemv711-chm.china.huawei.com (10.1.198.66) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256) id 15.1.2176.2; Tue, 10 Aug 2021 17:17:57 +0800 Received: from localhost.localdomain (10.67.165.2) by dggema757-chm.china.huawei.com (10.1.198.199) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_CBC_SHA256_P256) id 15.1.2176.2; Tue, 10 Aug 2021 17:17:57 +0800 From: Qi Liu To: , , , , , , CC: , , , , , , Subject: [PATCH v3 0/2] arm64: Enable OPTPROBE for arm64 Date: Tue, 10 Aug 2021 13:53:28 +0800 Message-ID: <20210810055330.18924-1-liuqi115@huawei.com> X-Mailer: git-send-email 2.17.1 MIME-Version: 1.0 X-Originating-IP: [10.67.165.2] X-ClientProxiedBy: dggems701-chm.china.huawei.com (10.3.19.178) To dggema757-chm.china.huawei.com (10.1.198.199) X-CFilter-Loop: Reflected X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210810_021803_957336_CBE3E3A5 X-CRM114-Status: GOOD ( 11.50 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org This patch introduce optprobe for ARM64, using a branch instruction to replace probed instruction. The test result on Hip08 platform is shown here, and optprobe could reduce the latency to 1/4 of normal kprobe kprobe before optimized: [280709.846380] do_empty returned 0 and took 1530 ns to execute [280709.852057] do_empty returned 0 and took 550 ns to execute [280709.857631] do_empty returned 0 and took 440 ns to execute [280709.863215] do_empty returned 0 and took 380 ns to execute [280709.868787] do_empty returned 0 and took 360 ns to execute [280709.874362] do_empty returned 0 and took 340 ns to execute [280709.879936] do_empty returned 0 and took 320 ns to execute [280709.885505] do_empty returned 0 and took 300 ns to execute [280709.891075] do_empty returned 0 and took 280 ns to execute [280709.896646] do_empty returned 0 and took 290 ns to execute [280709.902220] do_empty returned 0 and took 290 ns to execute [280709.907807] do_empty returned 0 and took 290 ns to execute optprobe: [ 2965.964572] do_empty returned 0 and took 90 ns to execute [ 2965.969952] do_empty returned 0 and took 80 ns to execute [ 2965.975332] do_empty returned 0 and took 70 ns to execute [ 2965.980714] do_empty returned 0 and took 60 ns to execute [ 2965.986128] do_empty returned 0 and took 80 ns to execute [ 2965.991507] do_empty returned 0 and took 70 ns to execute [ 2965.996884] do_empty returned 0 and took 70 ns to execute [ 2966.002262] do_empty returned 0 and took 80 ns to execute [ 2966.007642] do_empty returned 0 and took 70 ns to execute [ 2966.013020] do_empty returned 0 and took 70 ns to execute [ 2966.018400] do_empty returned 0 and took 70 ns to execute [ 2966.023779] do_empty returned 0 and took 70 ns to execute [ 2966.029158] do_empty returned 0 and took 70 ns to execute Changes since V2: - Address the comments from Masami, prepare another writable buffer in arch_prepare_optimized_kprobe()and build the trampoline code on it. - Address the comments from Amit, move save_all_base_regs and restore_all_base_regs to , as these two macros are reused in optprobe. - Link: https://lore.kernel.org/lkml/20210804060209.95817-1-liuqi115@huawei.com/ Changes since V1: - Address the comments from Masami, checks for all branch instructions, and use aarch64_insn_patch_text_nosync() instead of aarch64_insn_patch_text() in each probe. - Link: https://lore.kernel.org/lkml/20210719122417.10355-1-liuqi115@huawei.com/ Qi Liu (2): arm64: assembler: Make save_all_base_regs and restore_all_base_regs common macros arm64: kprobe: Enable OPTPROBE for arm64 arch/arm64/Kconfig | 1 + arch/arm64/include/asm/assembler.h | 52 ++++ arch/arm64/include/asm/kprobes.h | 24 ++ arch/arm64/kernel/probes/Makefile | 2 + arch/arm64/kernel/probes/kprobes.c | 19 +- arch/arm64/kernel/probes/kprobes_trampoline.S | 52 ---- arch/arm64/kernel/probes/opt_arm64.c | 239 ++++++++++++++++++ .../arm64/kernel/probes/optprobe_trampoline.S | 37 +++ 8 files changed, 371 insertions(+), 55 deletions(-) create mode 100644 arch/arm64/kernel/probes/opt_arm64.c create mode 100644 arch/arm64/kernel/probes/optprobe_trampoline.S