From patchwork Tue Aug 20 03:52:15 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 11102809 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 027591399 for ; Tue, 20 Aug 2019 03:52:21 +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 D43CC216F4 for ; Tue, 20 Aug 2019 03:52:20 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="VFhCgh36"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=Synaptics.onmicrosoft.com header.i=@Synaptics.onmicrosoft.com header.b="a8zC5qgk" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org D43CC216F4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=synaptics.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-ID:In-Reply-To: References:Message-ID:Date:Subject:To:From:Reply-To:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=5wBRZHXLEer7+seO+irYVGMZbWvx7vHIP6EfOXwIFo8=; b=VFhCgh36v3kkXs RlsfBOLHaMiGxMiuoCjFZSqHT0ILnLIEwtfaYdtPTTCElOOqt3b+i2u28PbbLrLTBnWga7Zx5YopO tNZQFw7VUTANLlvB6MgCOFLDiNlH/1Pwj2E2nc8UvLd4b5qSNZHhfbTvirA3YV0JmKJP4Rf+DCydi nWAXWgGVWdZYbXsY8BwL426F3LGPyWfl68W9OrVFMUqREHXrIzu/kcBDV1AArG9dXk3OxgUaNztat lhR+kXvOR8nuwMWHy6ybiPm6k5TIO/XzCZh5ScqrOoekB162udzYdh/NgRIBcN8crgo5YjUpLr2Z7 J6gHXn25MtJBjibzXdiA==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hzvBz-0001U7-L1; Tue, 20 Aug 2019 03:52:19 +0000 Received: from mail-eopbgr680047.outbound.protection.outlook.com ([40.107.68.47] helo=NAM04-BN3-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hzvBx-0001Ti-DP for linux-arm-kernel@lists.infradead.org; Tue, 20 Aug 2019 03:52:18 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=fpRyCxWibq62LWZw13MQWuRY3HgprpFLMOZCYXZFVR+EhzVh1BEMKNLfXdH8afh4srgunnfwGdfJm4D+qEqvenHNUB3AeYEfKfKskcNISoc5WCHalCIwPl+EWYHRXNM54QUmAt2u+97mFBH3uLCosr0m0zwg0eQ3oN5NJX+aYyD2C4eIJZoiRw+IYgg/Xaz88H+lQh6tboQqvyn9NutSHFgvCyQ+QnvDgeNVBZixUn3WKbYlX6yefezJFKECQnXgoDVEaYWnevM4SK0YXdooqI1J1fipBvUYSgpFZk9RAq9llMefsJrQh1SsAfVUXYi5Dbki6v8S6M5VkDN0XHBgwA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XMKnhsML/1Uy9u2aqC1p0utqYye/7YKAWdCMjGB4d0I=; b=CBBI12H8J0J4cXldOGV4t9fu+q1FW+byT+Y5cQdImEDZz+Tr4vH2ts9LLiQgx0/tESJnZpvi43FNuyGXKVDIvND+Fb5rYqQfJb21nepShApurvt5PRK/rcHJHFE49/y7phiapd7hsCn2yvFysW1BRUaDILtcjRYcevQ1yGnVT3S7IYZQGJRfcqF9WKpmzjhFqHJrmEiiHLyGnO/rVwoowKOHbansISjHU0FWUoWxr/DJH2cWsf3Ys5PqLPXiOIGzEcrbIHZLQ7r51UGbweW4jOzPVMOA8cM//4HzL8VXYB6RoEdvngVF+tWcwA1Ag54+kRY4uRHMsqAMx9byyJcOSg== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=synaptics.com; dmarc=pass action=none header.from=synaptics.com; dkim=pass header.d=synaptics.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Synaptics.onmicrosoft.com; s=selector2-Synaptics-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=XMKnhsML/1Uy9u2aqC1p0utqYye/7YKAWdCMjGB4d0I=; b=a8zC5qgkD9vagJmeSo1UfASI3tSdEcohdFC85pY1Ovb9H+mlJ45llFtilX7dQY+wMi1DO/KcysDt7T47g/ufNYdTDbQc+m72HfTw/nMl+EqVsjKF4Fqb09Zwkf5A0WStzMdnaDQresUBax2QHFns92dVUm1TsgD112kHh5S44Lo= Received: from BYAPR03MB4773.namprd03.prod.outlook.com (20.179.92.152) by BYAPR03MB4373.namprd03.prod.outlook.com (20.178.48.94) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2178.16; Tue, 20 Aug 2019 03:52:15 +0000 Received: from BYAPR03MB4773.namprd03.prod.outlook.com ([fe80::a517:3578:67bf:6c88]) by BYAPR03MB4773.namprd03.prod.outlook.com ([fe80::a517:3578:67bf:6c88%7]) with mapi id 15.20.2157.022; Tue, 20 Aug 2019 03:52:15 +0000 From: Jisheng Zhang To: Catalin Marinas , Jonathan Corbet , Will Deacon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , "x86@kernel.org" , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Masami Hiramatsu Subject: [PATCH v2 1/3] kprobes/x86: use instruction_pointer and instruction_pointer_set Thread-Topic: [PATCH v2 1/3] kprobes/x86: use instruction_pointer and instruction_pointer_set Thread-Index: AQHVVwqnz3HRGv5g102l5gAICz+hHg== Date: Tue, 20 Aug 2019 03:52:15 +0000 Message-ID: <20190820114109.4624d56b@xhacker.debian> References: <20190820113928.1971900c@xhacker.debian> In-Reply-To: <20190820113928.1971900c@xhacker.debian> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [124.74.246.114] x-clientproxiedby: TYAPR04CA0003.apcprd04.prod.outlook.com (2603:1096:404:15::15) To BYAPR03MB4773.namprd03.prod.outlook.com (2603:10b6:a03:134::24) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Jisheng.Zhang@synaptics.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 7e8b7161-0dc1-4479-6300-08d72521ca2a x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:BYAPR03MB4373; x-ms-traffictypediagnostic: BYAPR03MB4373: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8273; x-forefront-prvs: 013568035E x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(396003)(136003)(366004)(39860400002)(346002)(376002)(199004)(189003)(316002)(6506007)(102836004)(25786009)(6486002)(8676002)(2501003)(486006)(476003)(71190400001)(71200400001)(305945005)(6116002)(3846002)(7736002)(186003)(1076003)(386003)(86362001)(446003)(11346002)(26005)(76176011)(7416002)(52116002)(110136005)(54906003)(81166006)(14454004)(9686003)(5660300002)(66946007)(256004)(8936002)(66446008)(64756008)(81156014)(53936002)(66556008)(99286004)(66476007)(66066001)(478600001)(4326008)(2906002)(50226002)(6512007)(6436002)(921003)(1121003)(39210200001); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR03MB4373; H:BYAPR03MB4773.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; A:0; MX:1; received-spf: None (protection.outlook.com: synaptics.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: 3zRdRfhn4+IFxp3erj4gfrCkjT/dslFPe0psUFfB7/IGubdNv8AgAST1mUZRgadzIL9U2u17OO5j/fMn4sZtoRG0ytlvgxfXqa6LsU50ZKLhl18HTImOEggCLfpCAMkh5ob1D6imFoV6TeteXPTzhkBp+jNiOSkCEviR10eP9ecMvZPhU4sLnvFmKW8vAHthWrH62bX3HLBd5rmHewYfHZxkfZO31XoaWaVHA76Lwk/XyireOT38MzD0U1UMcnZlFg6skZQUsX449GA/gB5Ilg8Tf/zSpzIyFep31TjFox4pLTe98Lv1N/9esR/do6h7kaAHzNHy0HAOUIrvmSoQFM4eJPLsWeVLxbNmT91/Fic6zozVjAaxxMKbkmjk0te7Fvp3rxpRM8vnpw26gMkmuHmltHouIHGe+SZsA60Fo3o= x-ms-exchange-transport-forked: True Content-ID: <5E08BC2CF7D78542AF964F0A198BE2FA@namprd03.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-Network-Message-Id: 7e8b7161-0dc1-4479-6300-08d72521ca2a X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Aug 2019 03:52:15.5396 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 335d1fbc-2124-4173-9863-17e7051a2a0e X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: b1CWmgtcA0yFo10LmO/c2gE5e6borOYUHeyF/BSsKh4auGGqkLj7MbHwLSaAIsRWZL9Jo3GATo2D/47Wz/RFCw== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR03MB4373 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190819_205217_451010_24821995 X-CRM114-Status: GOOD ( 10.86 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [40.107.68.47 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-doc@vger.kernel.org" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org This is to make the x86 kprobe_ftrace_handler() more common so that the code could be reused in future. Signed-off-by: Jisheng Zhang Acked-by: Masami Hiramatsu --- arch/x86/kernel/kprobes/ftrace.c | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/arch/x86/kernel/kprobes/ftrace.c b/arch/x86/kernel/kprobes/ftrace.c index 681a4b36e9bb..c2ad0b9259ca 100644 --- a/arch/x86/kernel/kprobes/ftrace.c +++ b/arch/x86/kernel/kprobes/ftrace.c @@ -28,9 +28,9 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, if (kprobe_running()) { kprobes_inc_nmissed_count(p); } else { - unsigned long orig_ip = regs->ip; + unsigned long orig_ip = instruction_pointer(regs); /* Kprobe handler expects regs->ip = ip + 1 as breakpoint hit */ - regs->ip = ip + sizeof(kprobe_opcode_t); + instruction_pointer_set(regs, ip + sizeof(kprobe_opcode_t)); __this_cpu_write(current_kprobe, p); kcb->kprobe_status = KPROBE_HIT_ACTIVE; @@ -39,12 +39,13 @@ void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, * Emulate singlestep (and also recover regs->ip) * as if there is a 5byte nop */ - regs->ip = (unsigned long)p->addr + MCOUNT_INSN_SIZE; + instruction_pointer_set(regs, + (unsigned long)p->addr + MCOUNT_INSN_SIZE); if (unlikely(p->post_handler)) { kcb->kprobe_status = KPROBE_HIT_SSDONE; p->post_handler(p, regs, 0); } - regs->ip = orig_ip; + instruction_pointer_set(regs, orig_ip); } /* * If pre_handler returns !0, it changes regs->ip. We have to From patchwork Tue Aug 20 03:53:31 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 11102811 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 1251914DB for ; Tue, 20 Aug 2019 03:53:37 +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 E408F216F4 for ; Tue, 20 Aug 2019 03:53:36 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="bz5Xptp6"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=Synaptics.onmicrosoft.com header.i=@Synaptics.onmicrosoft.com header.b="QaRLnHir" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org E408F216F4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=synaptics.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-ID:In-Reply-To: References:Message-ID:Date:Subject:To:From:Reply-To:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TjLNuUcXJGusELCGwhPnlqJZ2cePdAP8PWMkDrY6PDk=; b=bz5Xptp6TtXePH oEqdU8SOOUr5FrhzkOdWhkPc153fm+/lkvxoUytrtUuT8ViaSP6MD9vAPcew5w+hdoS8IDkxNMBTV d9lVDCTYS+SEgxHW1Z45nrmOEb5GiPnRm6YeNdR7KgzW33D3q9mmmQtog4rHri537OIcbJojCrMlf AXQKk1/LWgpEd6RdWMd3pcJc9c/3Gi/VIi69JLkTW8PvzJOLLf44Ct0XhMPoZiHl6PF0ZT5AdgtRF MCYjM2xotxdbhWjgHhHS6DI7DCvx35biMrmCHzTzQfboche9Uzrr+qL34EHfBTjMAw4VKh8OtqbBC nETBk6ZESlXH1gwTtJsw==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hzvDD-0001jz-PQ; Tue, 20 Aug 2019 03:53:35 +0000 Received: from mail-eopbgr710056.outbound.protection.outlook.com ([40.107.71.56] helo=NAM05-BY2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hzvDB-0001je-2W for linux-arm-kernel@lists.infradead.org; Tue, 20 Aug 2019 03:53:34 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=F7q68aOII07dbCPVlZDbWL/VA4WV1ZTem58jonRUwqBzHS6aArLR2z3ojB65Gr42V8jz5c7K57GjHQ1hU9OzvGNFdcmaGWobDRYPoOAjVVC+107PCj+5OFk52e7LNxpiYcc3bFUM71C+uHlGuAFQY4/6R609FGytneVCm3evn/CWemhT10GptLSBHSefj+hyZrcCFZCsRtvzB3kI1PsOEVyVC6eYE8A+PTRcSn6W/20R0WqazfuqF78jItRknEZBP303fKbBIiycOMK095IeZUWqSB68HhOp3WKYwLWUHltz57Nm4zACJjicW0CvHALJh3XjYDKvyV58004Ran1rFg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=M6liWGvIujiyKQMbDLvytJ2ECSW3hXjgw7Be6M5leWU=; b=JEC0j0jBv5Fvy8EjBUTePLjBwbl6oepnpYpRk0tFoNXQ2QIzP7D9w4AygVLjLjBn1WCh8vcScKLZY0AQGwhwNldgp/JSs7DjGawkoy9y/V4Um3DMDhpN3EH1VcD/IHAQU2jyDpMtk5dgYNqEFA73C6Zz26U3ByQB3AfW/1fNpUuUUMIXYOCltCne4zE/Ljq8Rs9yhc0XxNByB07FXl8DDDaEDKYJPVCgMJ+Drc7eSEjcLjWelOcEz5tPZHTNN/pkjG+uGKSuoHmwZ80CPgKycObYumWfoqBRZvuUCbqUP0yF2oTzvxJ/bRXGD4aYWQ4ZmtmNPnMoXwbDvtyvMhe/4g== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=synaptics.com; dmarc=pass action=none header.from=synaptics.com; dkim=pass header.d=synaptics.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Synaptics.onmicrosoft.com; s=selector2-Synaptics-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=M6liWGvIujiyKQMbDLvytJ2ECSW3hXjgw7Be6M5leWU=; b=QaRLnHirbl599QEXr+mhGFW92RpiC3VmmFS76kctwTGFkyBquo5No4uLBhmQinsRWuHkSNHp2GLWPu37Cgay/MIRFETF8brueVBRgueDV5KHmm3Wk/kIquT9n9SZeULo5W1MxXIkTcZV8LCsC2i9WIZ+tcV1dINllIXucvCsCco= Received: from BYAPR03MB4773.namprd03.prod.outlook.com (20.179.92.152) by BYAPR03MB4870.namprd03.prod.outlook.com (20.179.93.215) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2157.16; Tue, 20 Aug 2019 03:53:31 +0000 Received: from BYAPR03MB4773.namprd03.prod.outlook.com ([fe80::a517:3578:67bf:6c88]) by BYAPR03MB4773.namprd03.prod.outlook.com ([fe80::a517:3578:67bf:6c88%7]) with mapi id 15.20.2157.022; Tue, 20 Aug 2019 03:53:31 +0000 From: Jisheng Zhang To: Catalin Marinas , Jonathan Corbet , Will Deacon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , "x86@kernel.org" , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Masami Hiramatsu Subject: [PATCH v2 2/3] kprobes: adjust kprobe addr for KPROBES_ON_FTRACE Thread-Topic: [PATCH v2 2/3] kprobes: adjust kprobe addr for KPROBES_ON_FTRACE Thread-Index: AQHVVwrVXMrB52r5zEm7ypsroIKAaw== Date: Tue, 20 Aug 2019 03:53:31 +0000 Message-ID: <20190820114224.0c8963c4@xhacker.debian> References: <20190820113928.1971900c@xhacker.debian> In-Reply-To: <20190820113928.1971900c@xhacker.debian> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [124.74.246.114] x-clientproxiedby: TY1PR01CA0180.jpnprd01.prod.outlook.com (2603:1096:402::32) To BYAPR03MB4773.namprd03.prod.outlook.com (2603:10b6:a03:134::24) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Jisheng.Zhang@synaptics.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 736b347f-b974-409b-2ee0-08d72521f77c x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:BYAPR03MB4870; x-ms-traffictypediagnostic: BYAPR03MB4870: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:1417; x-forefront-prvs: 013568035E x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(979002)(136003)(346002)(39860400002)(376002)(366004)(396003)(189003)(199004)(6116002)(6486002)(3846002)(53936002)(76176011)(2906002)(6436002)(86362001)(1076003)(64756008)(71190400001)(6512007)(110136005)(9686003)(6506007)(71200400001)(54906003)(66066001)(5660300002)(4326008)(14454004)(316002)(52116002)(66556008)(476003)(7736002)(99286004)(446003)(2501003)(486006)(386003)(8676002)(81166006)(66946007)(256004)(478600001)(50226002)(102836004)(8936002)(26005)(305945005)(66446008)(66476007)(7416002)(186003)(11346002)(25786009)(81156014)(921003)(39210200001)(1121003)(969003)(989001)(999001)(1009001)(1019001); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR03MB4870; H:BYAPR03MB4773.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:0; received-spf: None (protection.outlook.com: synaptics.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: jCr85pMSBpZf/iiTBNOAhYnJ5xFbTKe8X4xtmJrxBD1sszI8fCBxWBiAAZX9NObyVHX+0xGGFib9crGswXfiAyEZap4+Qu6pIhDxPfj3DJZqVLRXBlWdJF7e44bp7C47xf705mr5vrPAtB7g9b4RNUc0RCZFENiZsBMTtfxdLsCYQab2+04ApIhLbHSaHl+VR77t10kDwbOTH98GZzJAhAHxceZimhePqoMUbaOtLc5NdKHNhxNt4pzVaTUywHXLxFxNuq6zPav10heXZVs8okBbQ74ogUlEqhtU3U0ijRx0jB0DkghlpPiZg2MLxJKl6zPV4B8ZbqcHnMmL9ok89/SjIgMGd7hNEuz3IvCWCz0yj1Cey5ykRdFwCKKPbwABmImQOCewNI+6xYv2etadp0BEEK0vrgUK/9mJkJNG8+A= x-ms-exchange-transport-forked: True Content-ID: MIME-Version: 1.0 X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-Network-Message-Id: 736b347f-b974-409b-2ee0-08d72521f77c X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Aug 2019 03:53:31.5622 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 335d1fbc-2124-4173-9863-17e7051a2a0e X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: DVcKL1qaCY64uLm1mYUqT7Zuz8nHg1XeXtugrzuWZIjXzbRfk1okiEyjk1Mmgnk+ZT7yxJtG433sq+cGKgSicg== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR03MB4870 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190819_205333_117258_46748CD5 X-CRM114-Status: GOOD ( 12.87 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [40.107.71.56 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-doc@vger.kernel.org" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org For KPROBES_ON_FTRACE case, we need to adjust the kprobe's addr correspondingly. Signed-off-by: Jisheng Zhang --- kernel/kprobes.c | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 9873fc627d61..3fd2f68644da 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -1484,15 +1484,19 @@ static inline int check_kprobe_rereg(struct kprobe *p) int __weak arch_check_ftrace_location(struct kprobe *p) { - unsigned long ftrace_addr; + unsigned long ftrace_addr, addr = (unsigned long)p->addr; - ftrace_addr = ftrace_location((unsigned long)p->addr); +#ifdef CONFIG_KPROBES_ON_FTRACE + addr = ftrace_call_adjust(addr); +#endif + ftrace_addr = ftrace_location(addr); if (ftrace_addr) { #ifdef CONFIG_KPROBES_ON_FTRACE /* Given address is not on the instruction boundary */ - if ((unsigned long)p->addr != ftrace_addr) + if (addr != ftrace_addr) return -EILSEQ; p->flags |= KPROBE_FLAG_FTRACE; + p->addr = (kprobe_opcode_t *)addr; #else /* !CONFIG_KPROBES_ON_FTRACE */ return -EINVAL; #endif From patchwork Tue Aug 20 03:54:20 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 11102813 Return-Path: Received: from mail.kernel.org (pdx-korg-mail-1.web.codeaurora.org [172.30.200.123]) by pdx-korg-patchwork-2.web.codeaurora.org (Postfix) with ESMTP id 7583014DB for ; Tue, 20 Aug 2019 03:54:24 +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 4C4EA216F4 for ; Tue, 20 Aug 2019 03:54:24 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="TVbg0mMO"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=Synaptics.onmicrosoft.com header.i=@Synaptics.onmicrosoft.com header.b="Wm7aDHMd" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 4C4EA216F4 Authentication-Results: mail.kernel.org; dmarc=none (p=none dis=none) header.from=synaptics.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20170209; h=Sender: Content-Transfer-Encoding:Content-Type:Cc:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:MIME-Version:Content-ID:In-Reply-To: References:Message-ID:Date:Subject:To:From:Reply-To:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=63VMHQB1oGn0VKUlixNUCBVvh0UGIEW/XZoTRVUhDbk=; b=TVbg0mMOINQeKu pUYxTuvWs8Gps6zH5E7pneOXO85JtkJofnzlHnCQx0Auet1MQwHUEPChuxMVjCGbHST/rPeouI5YE sdwIRoFoKUZdnGpeB6vQumZ5jxusqukMgQjRzutOlf3JG+LTF75S7p4KpNo+fV5Jc3gjRHIHR/4sl bKXpppm31JouYPMH+uXqCVCL4Ve5/ydygw+/+ceykeUY1gLyNxUp4ANwvwAhrybhOxw3NAVGCdt8d 25kBBxH7T55G8PHCNbylALRLIB862zCuAuW5vOaBc4liJeZn8JhDjRi2DDJmoTnX4u/pMLukfRJEX VMLAVDwIrN/MfdNtrSig==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92 #3 (Red Hat Linux)) id 1hzvDz-0002Ee-RP; Tue, 20 Aug 2019 03:54:23 +0000 Received: from mail-eopbgr710056.outbound.protection.outlook.com ([40.107.71.56] helo=NAM05-BY2-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hzvDw-0002E0-TJ for linux-arm-kernel@lists.infradead.org; Tue, 20 Aug 2019 03:54:22 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=B1XdVSOvaXIQubruidpCcfxKTSG4Ubrm0475d8ZVb0PV/NmedUJ8IJvZeBpICbx2cgHJfRkA8ein7F+t6E2HMY6zW+rRqC01NRKyUm6FiZdNF5GwJXG6blNssXWq+4J/MfS6JeFOVEeGZ3cHkKeciVDOp5MU1Hm9vM7miYpgHXkotqvatecsNlBxyoYmnSs44SKrTgVGFAKbDvmt4uZkKJRfrTuDIJjkvkxua446EJSLhrBxlQmdW6PKIXzEiaVCFLggayFho6s7+cWv6uIgo6Zvy96bFKBPnuDkWHKP6MYULFVvi5UfMaWiyiIkZuJ2xOBQz4dDVeYMvr1P1riCrg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=microsoft.com; s=arcselector9901; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ErXupsvfk+tkZsOGpLtm1FI/DiDjRBvF0nj30oUOZh0=; b=A0QJFpLUhs6zJvu7JVcG78kl2d1SDtC4G+y26CNJufUVLN8C3Euweg34lXTMB9uhPpl0um9kyB7X3T9+DsjkPxgyXAQGcf98jBvCKGduqbG+mTmJ4+hXFQ9YXxmuO3MClamW/tKkLgruCXjZKW2gyoTTsCyC6AhemVo2IpQr/usDTZMtE+Y6F1rIhj4Rr/OZF8UX+VdTrw62LVLhh3bksoE0/Zc6+GCvsTJ60J5XeQF5EQufpJase8zUTvuaQZZ349iZzKlGBuJAb5CRBLIHbzjZ8vX2zPfYZ7B3u+1tvTvF1uq/3nDNbGke3w5lqAJa+n4h6yyy/+juR4Hm+pu74Q== ARC-Authentication-Results: i=1; mx.microsoft.com 1; spf=pass smtp.mailfrom=synaptics.com; dmarc=pass action=none header.from=synaptics.com; dkim=pass header.d=synaptics.com; arc=none DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=Synaptics.onmicrosoft.com; s=selector2-Synaptics-onmicrosoft-com; h=From:Date:Subject:Message-ID:Content-Type:MIME-Version:X-MS-Exchange-SenderADCheck; bh=ErXupsvfk+tkZsOGpLtm1FI/DiDjRBvF0nj30oUOZh0=; b=Wm7aDHMd1+sNydYOYpMVF+PWWvzZ9lyDguNk5ABmA8m6RSHLsLWgbpmuu5iMbA0IHSWsQWnhI/rdgMuyXyg5gbDqhooLv/Tr9A0B+uffZLYVqnmuyf2FZIkeaNjParVO8D/Q5PVERVD/R/JJJe+JYFjS6IQ7oKrQvTyC97/S5mg= Received: from BYAPR03MB4773.namprd03.prod.outlook.com (20.179.92.152) by BYAPR03MB4870.namprd03.prod.outlook.com (20.179.93.215) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2157.16; Tue, 20 Aug 2019 03:54:20 +0000 Received: from BYAPR03MB4773.namprd03.prod.outlook.com ([fe80::a517:3578:67bf:6c88]) by BYAPR03MB4773.namprd03.prod.outlook.com ([fe80::a517:3578:67bf:6c88%7]) with mapi id 15.20.2157.022; Tue, 20 Aug 2019 03:54:20 +0000 From: Jisheng Zhang To: Catalin Marinas , Jonathan Corbet , Will Deacon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , "x86@kernel.org" , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Masami Hiramatsu Subject: [PATCH v2 3/3] arm64: implement KPROBES_ON_FTRACE Thread-Topic: [PATCH v2 3/3] arm64: implement KPROBES_ON_FTRACE Thread-Index: AQHVVwryjSNW9eV9u0mDAvz7yXMGOw== Date: Tue, 20 Aug 2019 03:54:20 +0000 Message-ID: <20190820114314.685a3239@xhacker.debian> References: <20190820113928.1971900c@xhacker.debian> In-Reply-To: <20190820113928.1971900c@xhacker.debian> Accept-Language: en-US Content-Language: en-US X-MS-Has-Attach: X-MS-TNEF-Correlator: x-originating-ip: [124.74.246.114] x-clientproxiedby: TY2PR06CA0027.apcprd06.prod.outlook.com (2603:1096:404:2e::15) To BYAPR03MB4773.namprd03.prod.outlook.com (2603:10b6:a03:134::24) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Jisheng.Zhang@synaptics.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: Claws Mail 3.17.3 (GTK+ 2.24.32; x86_64-pc-linux-gnu) x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4cf07ffa-c85f-46fb-5508-08d72522145e x-microsoft-antispam: BCL:0; PCL:0; RULEID:(2390118)(7020095)(4652040)(8989299)(4534185)(4627221)(201703031133081)(201702281549075)(8990200)(5600148)(711020)(4605104)(1401327)(2017052603328)(7193020); SRVR:BYAPR03MB4870; x-ms-traffictypediagnostic: BYAPR03MB4870: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7219; x-forefront-prvs: 013568035E x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(346002)(39860400002)(376002)(366004)(396003)(189003)(199004)(6116002)(6486002)(3846002)(53936002)(76176011)(2906002)(6436002)(86362001)(1076003)(64756008)(71190400001)(6512007)(110136005)(9686003)(6506007)(71200400001)(54906003)(66066001)(5660300002)(4326008)(14454004)(316002)(52116002)(66556008)(476003)(7736002)(99286004)(446003)(2501003)(486006)(386003)(8676002)(14444005)(81166006)(66946007)(256004)(478600001)(50226002)(102836004)(8936002)(26005)(305945005)(66446008)(66476007)(7416002)(186003)(11346002)(25786009)(81156014)(921003)(39210200001)(1121003); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR03MB4870; H:BYAPR03MB4773.namprd03.prod.outlook.com; FPR:; SPF:None; LANG:en; PTR:InfoNoRecords; MX:1; A:0; received-spf: None (protection.outlook.com: synaptics.com does not designate permitted sender hosts) x-ms-exchange-senderadcheck: 1 x-microsoft-antispam-message-info: aCiZWPwy8Jwdi/+8CSI+xJM9idFvTBdYY4HlzBQTf8HwUnS/c4nJpic5UAvYidiJ6dtg4XAdC2K7Gd0LNqQFfQ4jgQS+31sJxp23Qva49gPylD2dTWoSPr2gg5qUlQcMR97ECGzM22nQnXyUrc+aDYK+DHrkaOl03hY29WpfiwtLc1F83yU30RzioHt75JvaXN5ADv9p/N+iNCT5VOAi23KHLuszvh8qaJdq+ALd/Z7zs37vSRzqTYUPP8H9eHB8rtAN+sJORY/TRKvdkmUlSIyjwp/qdjgMUvtHrmEweSNP3qR7PJJPsWidlwPWScegHfwDUYqZyMkB5QSWMN/muCpZCpBnmzS5RUJkqOJgrymiivETL8HyKWkjXvOTvGxZJwMiMG5HP2FkYNnkljePAj0JMgLz9pydgcVDsKhYAto= x-ms-exchange-transport-forked: True Content-ID: <758C392CCF526742B344A76B55289EB3@namprd03.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4cf07ffa-c85f-46fb-5508-08d72522145e X-MS-Exchange-CrossTenant-originalarrivaltime: 20 Aug 2019 03:54:20.0344 (UTC) X-MS-Exchange-CrossTenant-fromentityheader: Hosted X-MS-Exchange-CrossTenant-id: 335d1fbc-2124-4173-9863-17e7051a2a0e X-MS-Exchange-CrossTenant-mailboxtype: HOSTED X-MS-Exchange-CrossTenant-userprincipalname: CAcL2sqKhRE5cmCP02pDSD1yfO3F+kGxqmameVtbPHlnLTImORFfR/k7vWwSSIv5o1KHH5PMynr1R/LnJg29iA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR03MB4870 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190819_205420_944317_C8A60B7B X-CRM114-Status: GOOD ( 16.07 ) X-Spam-Score: 0.0 (/) X-Spam-Report: SpamAssassin version 3.4.2 on bombadil.infradead.org summary: Content analysis details: (0.0 points) pts rule name description ---- ---------------------- -------------------------------------------------- -0.0 RCVD_IN_DNSWL_NONE RBL: Sender listed at https://www.dnswl.org/, no trust [40.107.71.56 listed in list.dnswl.org] 0.0 SPF_NONE SPF: sender does not publish an SPF Record -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.1 DKIM_VALID Message has at least one valid DKIM or DK signature 0.1 DKIM_SIGNED Message has a DKIM or DK signature, not necessarily valid X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: "linux-kernel@vger.kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-doc@vger.kernel.org" Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+patchwork-linux-arm=patchwork.kernel.org@lists.infradead.org KPROBES_ON_FTRACE avoids much of the overhead with regular kprobes as it eliminates the need for a trap, as well as the need to emulate or single-step instructions. This patch implements KPROBES_ON_FTRACE for arm64. Tested on berlin arm64 platform. ~ # mount -t debugfs debugfs /sys/kernel/debug/ ~ # cd /sys/kernel/debug/ /sys/kernel/debug # echo 'p _do_fork' > tracing/kprobe_events before the patch: /sys/kernel/debug # cat kprobes/list ffffff801009fe28 k _do_fork+0x0 [DISABLED] after the patch: /sys/kernel/debug # cat kprobes/list ffffff801009ff54 k _do_fork+0x4 [DISABLED][FTRACE] Signed-off-by: Jisheng Zhang --- .../debug/kprobes-on-ftrace/arch-support.txt | 2 +- arch/arm64/Kconfig | 1 + arch/arm64/kernel/probes/Makefile | 1 + arch/arm64/kernel/probes/ftrace.c | 60 +++++++++++++++++++ 4 files changed, 63 insertions(+), 1 deletion(-) create mode 100644 arch/arm64/kernel/probes/ftrace.c diff --git a/Documentation/features/debug/kprobes-on-ftrace/arch-support.txt b/Documentation/features/debug/kprobes-on-ftrace/arch-support.txt index 68f266944d5f..e8358a38981c 100644 --- a/Documentation/features/debug/kprobes-on-ftrace/arch-support.txt +++ b/Documentation/features/debug/kprobes-on-ftrace/arch-support.txt @@ -9,7 +9,7 @@ | alpha: | TODO | | arc: | TODO | | arm: | TODO | - | arm64: | TODO | + | arm64: | ok | | c6x: | TODO | | csky: | TODO | | h8300: | TODO | diff --git a/arch/arm64/Kconfig b/arch/arm64/Kconfig index 663392d1eae2..928700f15e23 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -167,6 +167,7 @@ config ARM64 select HAVE_STACKPROTECTOR select HAVE_SYSCALL_TRACEPOINTS select HAVE_KPROBES + select HAVE_KPROBES_ON_FTRACE select HAVE_KRETPROBES select HAVE_GENERIC_VDSO select IOMMU_DMA if IOMMU_SUPPORT diff --git a/arch/arm64/kernel/probes/Makefile b/arch/arm64/kernel/probes/Makefile index 8e4be92e25b1..4020cfc66564 100644 --- a/arch/arm64/kernel/probes/Makefile +++ b/arch/arm64/kernel/probes/Makefile @@ -4,3 +4,4 @@ obj-$(CONFIG_KPROBES) += kprobes.o decode-insn.o \ simulate-insn.o obj-$(CONFIG_UPROBES) += uprobes.o decode-insn.o \ simulate-insn.o +obj-$(CONFIG_KPROBES_ON_FTRACE) += ftrace.o diff --git a/arch/arm64/kernel/probes/ftrace.c b/arch/arm64/kernel/probes/ftrace.c new file mode 100644 index 000000000000..52901ffff570 --- /dev/null +++ b/arch/arm64/kernel/probes/ftrace.c @@ -0,0 +1,60 @@ +// SPDX-License-Identifier: GPL-2.0-or-later +/* + * Dynamic Ftrace based Kprobes Optimization + * + * Copyright (C) Hitachi Ltd., 2012 + * Copyright (C) 2019 Jisheng Zhang + * Synaptics Incorporated + */ + +#include + +/* Ftrace callback handler for kprobes -- called under preepmt disabed */ +void kprobe_ftrace_handler(unsigned long ip, unsigned long parent_ip, + struct ftrace_ops *ops, struct pt_regs *regs) +{ + struct kprobe *p; + struct kprobe_ctlblk *kcb; + + /* Preempt is disabled by ftrace */ + p = get_kprobe((kprobe_opcode_t *)ip); + if (unlikely(!p) || kprobe_disabled(p)) + return; + + kcb = get_kprobe_ctlblk(); + if (kprobe_running()) { + kprobes_inc_nmissed_count(p); + } else { + unsigned long orig_ip = instruction_pointer(regs); + /* Kprobe handler expects regs->pc = pc + 1 as breakpoint hit */ + instruction_pointer_set(regs, ip + sizeof(kprobe_opcode_t)); + + __this_cpu_write(current_kprobe, p); + kcb->kprobe_status = KPROBE_HIT_ACTIVE; + if (!p->pre_handler || !p->pre_handler(p, regs)) { + /* + * Emulate singlestep (and also recover regs->pc) + * as if there is a nop + */ + instruction_pointer_set(regs, + (unsigned long)p->addr + MCOUNT_INSN_SIZE); + if (unlikely(p->post_handler)) { + kcb->kprobe_status = KPROBE_HIT_SSDONE; + p->post_handler(p, regs, 0); + } + instruction_pointer_set(regs, orig_ip); + } + /* + * If pre_handler returns !0, it changes regs->pc. We have to + * skip emulating post_handler. + */ + __this_cpu_write(current_kprobe, NULL); + } +} +NOKPROBE_SYMBOL(kprobe_ftrace_handler); + +int arch_prepare_kprobe_ftrace(struct kprobe *p) +{ + p->ainsn.api.insn = NULL; + return 0; +}