From patchwork Wed Dec 25 09:42:07 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 11310051 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 D044B138C for ; Wed, 25 Dec 2019 09:42:14 +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 AD55520722 for ; Wed, 25 Dec 2019 09:42:14 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="hrLuXUGj"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=Synaptics.onmicrosoft.com header.i=@Synaptics.onmicrosoft.com header.b="mdoO1Ok+" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org AD55520722 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=6mVzIe7mNFWEQIB/q1gV/rxja3fMqoARujIsKHV3p6g=; b=hrLuXUGjtkiyXb IzX7RIR0Hm48KNg5THolJi7YcrrSiB694Y9IDgDyf9oiUz+grY4D6s8fW8HqejymGLyVPhV7LZ+Fs TE203SwU+YT0qxCGikzL7Bq4Hsli3XTvyxLn7SI5qVyUu7giratI7AB8PMMQPDFdV9S9F3KTne80a 81z5rXZFHLbRfbRPAzcn2CxQKokKOymEr4p7q/nx2vVlIMJ29oDLS63Vo/NBirWH0FNa+dJTZZSRz 7EidcmvhIn1AZxo8yli6V3e/LZzw1ACElaTrzJ4bOgDAzOsSmp/Qa7J7BbGj+KMbt2QR3iCeVWQvs z0fGzPkrbOFqKCHcS1UQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ik3BF-0002Va-JH; Wed, 25 Dec 2019 09:42:13 +0000 Received: from mail-bn8nam11on2061.outbound.protection.outlook.com ([40.107.236.61] helo=NAM11-BN8-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ik3BC-0002VE-74 for linux-arm-kernel@lists.infradead.org; Wed, 25 Dec 2019 09:42:11 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=GmDzoU6LfS9861GwusgyfGrjrU3lbkGZE+BEEsyfqcElBcBcq3SIovvoI8h4RtPiy4xTonIT5u5wSzqUTXtARAICkQbidXTLlRRcv9jWLx7PoMmDlkILqT+p9CbxFhSV5y+VuLqwJuGpUVN+zGgMwK5gsYDKBmdDKG9LlhgPHYDwxEr5DJa+6N6Hx4OMW7+bHWlqdDBa6YudH70vHfFf59Qrvhe/sfGnYMUVr9tlNhcNbdXMD3VObn6HROG6C1DyErazthygLUd2q7j1sXjsoo0++DHcjOCqs8qAkqlk/WFuveMyCT8ZdNaU+aoxWnLSprvy0ZLp+rzV/0n1z5L8Sg== 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=ILbzOurn3R6bsV0bRaBNRAdQHJ40b9HcElY3vUMCP8M=; b=FlNjpLEkMnrZRYmQ3Xd2ihGjAt97roUNI8rISZXk4rNXGn0IYSk3RZkPbntfc9WsbSmGWYpJXsn7wmewwjBIdbphTLNFdGwG2mQI2gLz3KRIYR0PBWDy2lxoFpITMbKDjVZCzgpI+Lif/MIAZrsWj3776svZ2yKt60teUsOJogz0ZJ9l7qQC6Vfi5w/99RyPDNaBEdaXlm2TXefSzKqFf/0y6tvZu/yiQsq706gi6fCMXhfykjsh+JZ3DWCTLB2a7kum3minon5zIZZuX7UK0Z/gB3uLo0qQYAkJ31fwfPK4ADDh2AGKewkCB0X172BgWBor+TfRPV9fFlMKQ9zV2w== 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=ILbzOurn3R6bsV0bRaBNRAdQHJ40b9HcElY3vUMCP8M=; b=mdoO1Ok+O6dK+kPx9NkC7cOAOp+PVixC6acesVQdcdv2lS5us+VdFxjZfD6ZirQWaDolDT+K6dQT3jsgQSgSB1XQMnEn8DAyCwnl+cJCkBKor4LFgGkaGYsQxPLvRdE6WV0pldhD3ZKYXkraX20sTFBeRJ5am0LbKEm5H+qKyhE= Received: from BYAPR03MB4773.namprd03.prod.outlook.com (20.179.93.213) by BYAPR03MB4661.namprd03.prod.outlook.com (20.179.91.218) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2581.11; Wed, 25 Dec 2019 09:42:07 +0000 Received: from BYAPR03MB4773.namprd03.prod.outlook.com ([fe80::708d:91cc:79a7:9b9a]) by BYAPR03MB4773.namprd03.prod.outlook.com ([fe80::708d:91cc:79a7:9b9a%6]) with mapi id 15.20.2559.017; Wed, 25 Dec 2019 09:42:07 +0000 Received: from xhacker.debian (124.74.246.114) by TYAPR01CA0196.jpnprd01.prod.outlook.com (2603:1096:404:29::16) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2581.11 via Frontend Transport; Wed, 25 Dec 2019 09:42:04 +0000 From: Jisheng Zhang To: Catalin Marinas , Will Deacon , Steven Rostedt , Ingo Molnar , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Masami Hiramatsu , Mark Rutland , Jonathan Corbet Subject: [PATCH v7 1/3] kprobes/ftrace: Use ftrace_location() when [dis]arming probes Thread-Topic: [PATCH v7 1/3] kprobes/ftrace: Use ftrace_location() when [dis]arming probes Thread-Index: AQHVuweSj3f0oMePuk6TgrRxmwYaVQ== Date: Wed, 25 Dec 2019 09:42:07 +0000 Message-ID: <20191225172752.70be1dc1@xhacker.debian> References: <20191225172625.69811b3e@xhacker.debian> In-Reply-To: <20191225172625.69811b3e@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: TYAPR01CA0196.jpnprd01.prod.outlook.com (2603:1096:404:29::16) To BYAPR03MB4773.namprd03.prod.outlook.com (2603:10b6:a03:139::21) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Jisheng.Zhang@synaptics.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 0fce643c-9505-4d9c-7898-08d7891eb4e6 x-ms-traffictypediagnostic: BYAPR03MB4661: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:9508; x-forefront-prvs: 02622CEF0A x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(136003)(346002)(376002)(396003)(39850400004)(366004)(189003)(199004)(1076003)(81166006)(26005)(81156014)(55016002)(9686003)(8936002)(4326008)(186003)(7696005)(66946007)(86362001)(16526019)(8676002)(478600001)(52116002)(66556008)(6506007)(66446008)(64756008)(66476007)(956004)(110136005)(54906003)(7416002)(316002)(5660300002)(2906002)(71200400001)(921003)(1121003)(39210200001); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR03MB4661; 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: BCL:0; x-microsoft-antispam-message-info: iIDb2lOmzzDlxYnZeyTCHC3IYK4mua/N1x0+UwRDYs8KKGunuBNNy4C7CxyD6hY97nJ6ur7cRkPjDW6xDGqUZkx5g6M3aRZDYM3FmlcqaCPAugp5M823a2wF91+rXCV4nY+K55LlwJXT9Yu24ftf19evsO7WrXC+q6DsvVBCbC3Mtmda4KqTQ99rJHka9rNE5QoCanCEcwzevEp2v+8Ufv16PiKbNgYNCAt0aZsj8N6gRHgFP+wPu1lw0ui9Mjy6l7U5KeanfNIScgpgB+lNr5tQJDn5bL7ZpyqWT/dJjzww3xafexbhEWp5CUHegNiwKQOV49lVbdulpyk0mAmxLRvZ8wyjjAQ+F91P6FywEVcEvFUhJQ5nR2L9ui0fat5dApiCvkJ7qK46RZzq7DAolKv21AYdaFf3pqPqyKnZbcmYHO2/FOwyJCuaokTM4r7hL5UXluy+CCl+HfbB70Bje0sf99IfaHV38Ycz0bFu79dozYT9J6v68h4qTS2Vs5THBHOmv7SctDzeDGt7BOcCIVNhq61ceYDw2jcLbDWLoSk= x-ms-exchange-transport-forked: True Content-ID: MIME-Version: 1.0 X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-Network-Message-Id: 0fce643c-9505-4d9c-7898-08d7891eb4e6 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Dec 2019 09:42:07.5320 (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: pMJT/VD22Zhwy7J2nasGbiPwPwvKs/0auBK8J+jYjxEnY3P/yBSIA2TxKNi0SlJPvLwH/dRU0fGYABQ/8GJ18Q== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR03MB4661 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191225_014210_257166_E202281E X-CRM114-Status: GOOD ( 13.00 ) 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.236.61 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender 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 Ftrace location could include more than a single instruction in case of some architectures (powerpc64, for now). In this case, kprobe is permitted on any of those instructions, and uses ftrace infrastructure for functioning. However, [dis]arm_kprobe_ftrace() uses the kprobe address when setting up ftrace filter IP. This won't work if the address points to any instruction apart from the one that has a branch to _mcount(). To resolve this, have [dis]arm_kprobe_ftrace() use ftrace_function() to identify the filter IP. Signed-off-by: Naveen N. Rao Acked-by: Masami Hiramatsu --- kernel/kprobes.c | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/kernel/kprobes.c b/kernel/kprobes.c index 53534aa258a6..5c630b424e3a 100644 --- a/kernel/kprobes.c +++ b/kernel/kprobes.c @@ -986,9 +986,10 @@ static int prepare_kprobe(struct kprobe *p) static int __arm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops, int *cnt) { + unsigned long ftrace_ip = ftrace_location((unsigned long)p->addr); int ret = 0; - ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 0, 0); + ret = ftrace_set_filter_ip(ops, ftrace_ip, 0, 0); if (ret) { pr_debug("Failed to arm kprobe-ftrace at %pS (%d)\n", p->addr, ret); @@ -1011,7 +1012,7 @@ static int __arm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops, * At this point, sinec ops is not registered, we should be sefe from * registering empty filter. */ - ftrace_set_filter_ip(ops, (unsigned long)p->addr, 1, 0); + ftrace_set_filter_ip(ops, ftrace_ip, 1, 0); return ret; } @@ -1028,6 +1029,7 @@ static int arm_kprobe_ftrace(struct kprobe *p) static int __disarm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops, int *cnt) { + unsigned long ftrace_ip = ftrace_location((unsigned long)p->addr); int ret = 0; if (*cnt == 1) { @@ -1038,7 +1040,7 @@ static int __disarm_kprobe_ftrace(struct kprobe *p, struct ftrace_ops *ops, (*cnt)--; - ret = ftrace_set_filter_ip(ops, (unsigned long)p->addr, 1, 0); + ret = ftrace_set_filter_ip(ops, ftrace_ip, 1, 0); WARN_ONCE(ret < 0, "Failed to disarm kprobe-ftrace at %pS (%d)\n", p->addr, ret); return ret; From patchwork Wed Dec 25 09:42:52 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 11310053 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 E7794138C for ; Wed, 25 Dec 2019 09:42:58 +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 C48F120722 for ; Wed, 25 Dec 2019 09:42:58 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="RQLPQzAg"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=Synaptics.onmicrosoft.com header.i=@Synaptics.onmicrosoft.com header.b="kINL7k5B" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org C48F120722 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=f9wYweAq6SYPhR15TLKKZa/w2B2+Qis1OIjgmoUHQSQ=; b=RQLPQzAgohKqSu S/QTXckPwNCH+tM1MQVKK33ZzzqjCFT5vEJQLtYrrPVajUFNnJvjCXb6hQ80WoYKbid04lPlITMCZ FXYThayz/ffgAa9MIBPp42XDllhiPZBOv4GsggR1IA11+JO4nmu6i5+5qaPrVWAnkH2SHc8hXbCUX 4V+NIOPAQLyNcV1GEf5SiDe8TnflKcaoCnGNA4orWuSu3QPwqwPNkLzzuThyzxUWYUarvXhP1et09 1taHQe2+GDh6Y80sTmbrUaNxv9TAcrOWJnA3eTXGs/gE/c5EPNRRfXqN5Poz5h3NXKEjXJpsxHiQ+ i+MJENsfXJzCU8N8rW5g==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ik3Bx-0002q5-WD; Wed, 25 Dec 2019 09:42:58 +0000 Received: from mail-co1nam11on2063.outbound.protection.outlook.com ([40.107.220.63] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ik3Bv-0002pl-UP for linux-arm-kernel@lists.infradead.org; Wed, 25 Dec 2019 09:42:57 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=c+qbiN+U6x2ytoBoM74oVZn7czVVgVbJncBfXa0oHpWOZP2gxc4Nn/NYH35BaEyqhmDgx4yK7yYKLOaIbMtTskKFfgC5F+4aLje8t74nHAXdzHrgTXSJoupbB/KQz+Dht8bIw42n45QHUVYQzeqbG6GCoX2dP0QktHF9qc3Mkb5QtVSNRXuxzqY/qUJ94gTVm/DWeQnoYy7PodPASChODX27bI3yS2lWs4+cMBzlwafoSSt9VJapZMt0g9RK7BIeOQcLOzU3H7eJAu15coZOr67BLscDMRqytL1p7pwZ9KJjMxPC77r3e/1cesh7YdVC02W0igtJbwHtL/EwovwgBQ== 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=ICoQ2OQzX55MiUgYN1zoHHYBWdV5Zm3IcBDHqsGI63o=; b=FIDy7ENF/EVFeab3xWPFWjxN/Mos86MEnezHAN7KExSG2O7gsAjUxADKiqUx0yzC5eG0Qa1kqvQnBPoPB3m3E/GHua7BLJOiCe/4tWmPPLc/xVwe44m6ji5RDVRnTy4nh+ddrdGAwRigI5T1kvXbNVaiS2JuzwfiRgH5rDCI4ZcRwTsVIoaG63JJvOYUNrUtFIw9K8N0yohQ2ChyL3HtwfUxsRqn6RA5BTyH3Gijcul2SnGP1zT7J61PA5Ut1kRIAtH475TIQOHsEg4HszvE5S8u5IarRTqOBtQ2Yx/eH1QP26XW800RfSQY+NA2322aI+7eSfL4483b/krbD3S23g== 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=ICoQ2OQzX55MiUgYN1zoHHYBWdV5Zm3IcBDHqsGI63o=; b=kINL7k5BQWvh8Owf6Hj+e4qLgij9GXjbKD5IV96jL9pQCPaX0VSWu9BLMJa1D+5+EsVlWSYpyRswWfmpa4CEj3uEO2tCLTB5FGIs7ZQYzrNePl2QU1SfBruMduOQVIGKhdHhyBQ1XBwS+Ock08WkxFE+UpzZDOxOzd0GFzBymqA= Received: from BYAPR03MB4773.namprd03.prod.outlook.com (20.179.93.213) by BYAPR03MB4213.namprd03.prod.outlook.com (20.177.185.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2581.11; Wed, 25 Dec 2019 09:42:52 +0000 Received: from BYAPR03MB4773.namprd03.prod.outlook.com ([fe80::708d:91cc:79a7:9b9a]) by BYAPR03MB4773.namprd03.prod.outlook.com ([fe80::708d:91cc:79a7:9b9a%6]) with mapi id 15.20.2559.017; Wed, 25 Dec 2019 09:42:52 +0000 Received: from xhacker.debian (124.74.246.114) by TY2PR02CA0041.apcprd02.prod.outlook.com (2603:1096:404:a6::29) with Microsoft SMTP Server (version=TLS1_2, cipher=) via Frontend Transport; Wed, 25 Dec 2019 09:42:49 +0000 From: Jisheng Zhang To: Catalin Marinas , Will Deacon , Steven Rostedt , Ingo Molnar , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Masami Hiramatsu , Mark Rutland , Jonathan Corbet Subject: [PATCH v7 2/3] ftrace: introduce FTRACE_IP_EXTENSION Thread-Topic: [PATCH v7 2/3] ftrace: introduce FTRACE_IP_EXTENSION Thread-Index: AQHVuwet+NDQHpTM7km5hPNb6KsFRg== Date: Wed, 25 Dec 2019 09:42:52 +0000 Message-ID: <20191225172836.7f381759@xhacker.debian> References: <20191225172625.69811b3e@xhacker.debian> In-Reply-To: <20191225172625.69811b3e@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: TY2PR02CA0041.apcprd02.prod.outlook.com (2603:1096:404:a6::29) To BYAPR03MB4773.namprd03.prod.outlook.com (2603:10b6:a03:139::21) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Jisheng.Zhang@synaptics.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 52e3ef56-3cf4-4e14-aca6-08d7891ecf9d x-ms-traffictypediagnostic: BYAPR03MB4213: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:7219; x-forefront-prvs: 02622CEF0A x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39850400004)(366004)(346002)(136003)(396003)(376002)(189003)(199004)(9686003)(1076003)(5660300002)(86362001)(55016002)(6666004)(66476007)(956004)(66946007)(66556008)(64756008)(81156014)(8936002)(81166006)(8676002)(66446008)(16526019)(71200400001)(2906002)(26005)(186003)(52116002)(7696005)(7416002)(6506007)(4326008)(316002)(54906003)(110136005)(478600001)(921003)(1121003)(39210200001); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR03MB4213; 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: BCL:0; x-microsoft-antispam-message-info: pHCMS+N4PedcKcydfeW5MFMk1UmdhAJjCx/K23t2O4aU16724KD2DebaOiFaSmjEyHA+jlia9kIw3xXnM2dbMM4ZFIp+PTskcqPs79B3i6lwJUyiQqW4C0CtekcU49RaElJ9IOWy4vuOfeJX3WMHm7HvnG4PiNxsy01cccJKc4ezorhsH+JzbTm1znX40jUWBFMZ4SCZ61vgpmV0OK4zeVf88o8QST+lXPh2SEAq1fAYawHUclGbVOv/oFChv1Le/5KfsvlxhqEMHtiyLzOktyy7HO/dcAi1ZSfCIU300ZJTsBCO3emmfbjuDv6EMvi2wqS+rOhzXTsreR2H4pDBz0rq1b4AzjhNEfwb+asUb12ei+c+F6/RO4ASswuEJuVBUo9+16Yirh5DecvxUudU6iFpbuwXPChO+GZDPHDFAUGQX36hgZmkSxr3X4nGI4sMm1IhneXSiG4OlWYvn5RcPBPXAAWpsiCyb5TaLMmozP4kOL//pRz16wU8AkDCkWnVB7Bzsv2yqepvBKMVph7QNsH71Q629dWsbZvQFarwb2E= x-ms-exchange-transport-forked: True Content-ID: MIME-Version: 1.0 X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-Network-Message-Id: 52e3ef56-3cf4-4e14-aca6-08d7891ecf9d X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Dec 2019 09:42:52.4104 (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: b9rqria0Z1RJA/m9TirY3m17kvTfqUv/AqWB4gCaw5Z2h03CtmGW7OcG9wmOtj3+8AnYfLfCBoSRc3Axr6A5uA== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR03MB4213 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191225_014255_977829_CD973D86 X-CRM114-Status: GOOD ( 12.27 ) 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.220.63 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender 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 On some architectures, the DYNAMIC_FTRACE_WITH_REGS is implemented by gcc's -fpatchable-function-entry option. Take arm64 for example, arm64 makes use of GCC -fpatchable-function-entry=2 option to insert two nops. When the function is traced, the first nop will be modified to the LR saver, then the second nop to "bl ". we need to update ftrace_location() to recognise these two instructions as being part of ftrace. To do this, we introduce FTRACE_IP_EXTENSION to let ftrace_location search IP, IP + FTRACE_IP_EXTENSION range. Signed-off-by: Jisheng Zhang Suggested-by: Steven Rostedt (VMware) Reviewed-by: Masami Hiramatsu Reviewed-by: Steven Rostedt (VMware) --- include/linux/ftrace.h | 4 ++++ kernel/trace/ftrace.c | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/include/linux/ftrace.h b/include/linux/ftrace.h index 7247d35c3d16..05a03b2a2f39 100644 --- a/include/linux/ftrace.h +++ b/include/linux/ftrace.h @@ -20,6 +20,10 @@ #include +#ifndef FTRACE_IP_EXTENSION +#define FTRACE_IP_EXTENSION 0 +#endif + /* * If the arch supports passing the variable contents of * function_trace_op as the third parameter back from the diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c index 74439ab5c2b6..a8cfea502369 100644 --- a/kernel/trace/ftrace.c +++ b/kernel/trace/ftrace.c @@ -1590,7 +1590,7 @@ unsigned long ftrace_location_range(unsigned long start, unsigned long end) */ unsigned long ftrace_location(unsigned long ip) { - return ftrace_location_range(ip, ip); + return ftrace_location_range(ip, ip + FTRACE_IP_EXTENSION); } /** From patchwork Wed Dec 25 09:44:21 2019 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jisheng Zhang X-Patchwork-Id: 11310055 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 A56C913A4 for ; Wed, 25 Dec 2019 09:44:27 +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 801672073B for ; Wed, 25 Dec 2019 09:44:27 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="FCRe/+to"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=Synaptics.onmicrosoft.com header.i=@Synaptics.onmicrosoft.com header.b="ejx9dtWA" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 801672073B 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=N/wrKQl7gOpcZpPtFzZSAEiX2Zf45aJvYbCQ7oMxjDw=; b=FCRe/+toe40BX4 nKZqa2SN2n6gIwAhK2CyCa+zqDLbX2tiCdybdZBQXL1W5/OQAOUZ2ahjtkg4/Xn6Evk3hhYRjtowX KcrSkdwPH6G9Ud+r3TLxUxNEOc2R8ckuxcCWn3rSj/VyMjEhDUEhNGt8wUtQ614jzCgmTFSJU89IH 0sY0+IdhCVmojYHA15l3ZMCYJ4M0F33CJ1+HgHRD2R/RyE1j3OI4/O/LUoNlYYc2I0DUSDmZwr4tb gqUcCbKiiAr1sz97N6GarKdEtXogXk953m3sbUp4KvybcWOMtP4SSvTBesr8DujeiZK17Jjjmon/s 2durw/cv4D9AZfBfPvPQ==; Received: from localhost ([127.0.0.1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.92.3 #3 (Red Hat Linux)) id 1ik3DO-0003HE-V7; Wed, 25 Dec 2019 09:44:26 +0000 Received: from mail-co1nam11on2055.outbound.protection.outlook.com ([40.107.220.55] helo=NAM11-CO1-obe.outbound.protection.outlook.com) by bombadil.infradead.org with esmtps (Exim 4.92.3 #3 (Red Hat Linux)) id 1ik3DL-0003Gs-03 for linux-arm-kernel@lists.infradead.org; Wed, 25 Dec 2019 09:44:24 +0000 ARC-Seal: i=1; a=rsa-sha256; s=arcselector9901; d=microsoft.com; cv=none; b=kLMqYyVlQcRLt9oEkoLqgxe75M4Ny6KuVvqgdvn6frJfQTD0lZ+TbgV0echaNX8r6wfy42QZoSp3TVTaLqVy3T7w2qvDqk1ob0YgaC9iVfropQrPMWd+V18a1gV544doplK962AsEseeCBBxY/mdpMFkpBgV5/MDLX9pHpgdAtgvChvetEQMV3FTWNYuNUH6ymXPcmEZ3qjEGpmG4AuFeT0HOv0MdQUbjko4gOlaBY1dg/gPgbmY3STetIPRyMkokK/M9B30SYrCVcjiTxIXYnZbmNO8frRSor+W4M/DQHw2hr+aDBq0ign/0kfKL1CJ3vMm92DR1o94DNodew4V6Q== 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=DNFnhfAwfMMzPOlk3mgBi06/5bPmYts25Ajl13pw9z4=; b=bGr8OXOwnz13HwcuuuKp8AV3f2/oa52ztZTurnxyWd5OR+qyLIqHh6xxrwXCBOUjukEam9bL+CcBojd7Om74rGkjwqxa1cMiKKqPrOHcvKvyQ2kxcYlFOsB0LtMJ1/RpRw1J0s0qrxsSwwSuIHGuvmMvdmLKKtnFknv3Z6zzjDk23Zgz0zGtXma2VuD37ssFfJ1pB9f9V64vRpq+k60vjzUb4rkAmY4u89KBVyEPJybgnviGrQrHSiWwP38xg+VrIMKViLsSYYce73eF8DU34wf9F8wUhZBFq2yCvAjyrA1fcn6YPUX6Y0JzFGREfmW1xfCoIP+bLHtmWit3HAydeg== 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=DNFnhfAwfMMzPOlk3mgBi06/5bPmYts25Ajl13pw9z4=; b=ejx9dtWAmEXsvBuryENM3mNIpi95nDCrB62JylZtN56J02jxf/BqmVLcJqGuw+o2h+GF/EF+orrF97lrkVlDcpfUUM11N67tRkHbYrsB5ur9O79IkZH0biiZl/bxaosPN0kpQ7yCRdaJzl2hCT1PO6Ug9bepy1QnODD5YUrncdc= Received: from BYAPR03MB4773.namprd03.prod.outlook.com (20.179.93.213) by BYAPR03MB4213.namprd03.prod.outlook.com (20.177.185.209) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2581.11; Wed, 25 Dec 2019 09:44:21 +0000 Received: from BYAPR03MB4773.namprd03.prod.outlook.com ([fe80::708d:91cc:79a7:9b9a]) by BYAPR03MB4773.namprd03.prod.outlook.com ([fe80::708d:91cc:79a7:9b9a%6]) with mapi id 15.20.2559.017; Wed, 25 Dec 2019 09:44:21 +0000 Received: from xhacker.debian (124.74.246.114) by TYAPR01CA0168.jpnprd01.prod.outlook.com (2603:1096:404:7e::36) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_256_GCM_SHA384) id 15.20.2581.11 via Frontend Transport; Wed, 25 Dec 2019 09:44:18 +0000 From: Jisheng Zhang To: Catalin Marinas , Will Deacon , Steven Rostedt , Ingo Molnar , "Naveen N. Rao" , Anil S Keshavamurthy , "David S. Miller" , Masami Hiramatsu , Mark Rutland , Jonathan Corbet Subject: [PATCH v7 3/3] arm64: implement KPROBES_ON_FTRACE Thread-Topic: [PATCH v7 3/3] arm64: implement KPROBES_ON_FTRACE Thread-Index: AQHVuwfioeAAP6kOPkCZLC/0/SnpxA== Date: Wed, 25 Dec 2019 09:44:21 +0000 Message-ID: <20191225173001.6c0e3fb2@xhacker.debian> References: <20191225172625.69811b3e@xhacker.debian> In-Reply-To: <20191225172625.69811b3e@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: TYAPR01CA0168.jpnprd01.prod.outlook.com (2603:1096:404:7e::36) To BYAPR03MB4773.namprd03.prod.outlook.com (2603:10b6:a03:139::21) authentication-results: spf=none (sender IP is ) smtp.mailfrom=Jisheng.Zhang@synaptics.com; x-ms-exchange-messagesentrepresentingtype: 1 x-mailer: Claws Mail 3.17.4 (GTK+ 2.24.32; x86_64-pc-linux-gnu) x-ms-publictraffictype: Email x-ms-office365-filtering-correlation-id: 4106d40f-e7a1-4485-4aa1-08d7891f0492 x-ms-traffictypediagnostic: BYAPR03MB4213: x-microsoft-antispam-prvs: x-ms-oob-tlc-oobclassifiers: OLM:8882; x-forefront-prvs: 02622CEF0A x-forefront-antispam-report: SFV:NSPM; SFS:(10009020)(39850400004)(366004)(346002)(136003)(396003)(376002)(189003)(199004)(9686003)(1076003)(5660300002)(86362001)(55016002)(6666004)(66476007)(956004)(66946007)(66556008)(64756008)(81156014)(8936002)(81166006)(8676002)(66446008)(16526019)(71200400001)(2906002)(26005)(186003)(52116002)(7696005)(7416002)(6506007)(4326008)(316002)(54906003)(110136005)(478600001)(921003)(1121003)(39210200001); DIR:OUT; SFP:1101; SCL:1; SRVR:BYAPR03MB4213; 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: BCL:0; x-microsoft-antispam-message-info: qe5daeSEQp6IpLLal2rSFPFUy80TKDmRWbiDpnA6rvm3SwgYs9LI9732m9WsmOU9oodCMXErKEQXyRWb0iFceRp0zLPC9cJk5gkGArW7yAyvfp7GmGoVcxO0Vo274h4h3gLHqc0Uawat+z1DKys2J+wOz4q+FCmhDHKg8VkOtrRjvq850CdeyX1ElenhUP7PEY34cS+Yy4u+o+w3gimFhIEElKuYgCYkdcGXJv2HTsEn8H80i6skXm1Bvxf1C+OJmA3u7kCsISBvp7yglyCw03B2CItcdcG9vd+hZZ1t2/SlZSVEffiq5EzgGtVbO50vW0WiyYqFuio+NXxLx+UlaZUwFgWu3/+q73mwv0+tb/yiElcXThNR9NzvWO/WXH4l/ZbL5G3Am369PtzYLXfz5mxT2XxCwdMvrJGdzXROUGTVSHsqv8wBIoNRo+QeWTWhgp5pr54vx4cCSixLo58Zf/+XYlxMwUXNFyQqyxqs1Xkprm05nBCT6iYe+BQ/Ly+7A0eUL7246cw0gdJ0ZPwolLClxxXB52ndqIQET4m161c= x-ms-exchange-transport-forked: True Content-ID: <8741C552ACA29C499EFE21A17323E8BC@namprd03.prod.outlook.com> MIME-Version: 1.0 X-OriginatorOrg: synaptics.com X-MS-Exchange-CrossTenant-Network-Message-Id: 4106d40f-e7a1-4485-4aa1-08d7891f0492 X-MS-Exchange-CrossTenant-originalarrivaltime: 25 Dec 2019 09:44:21.2570 (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: Qwq/ACW2b9vIAfuNX8IrzgOIYqXej80NUZiO0hnnmZB5GTqfcmUbvSEaf0eRdRj2uSbI1YIlyGIOGwFx2g6AeQ== X-MS-Exchange-Transport-CrossTenantHeadersStamped: BYAPR03MB4213 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20191225_014423_044299_790C7059 X-CRM114-Status: GOOD ( 15.43 ) 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.220.55 listed in list.dnswl.org] -0.0 SPF_HELO_PASS SPF: HELO matches SPF record -0.0 SPF_PASS SPF: sender 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. 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+0x0 [DISABLED][FTRACE] Signed-off-by: Jisheng Zhang --- .../debug/kprobes-on-ftrace/arch-support.txt | 2 +- arch/arm64/Kconfig | 1 + arch/arm64/include/asm/ftrace.h | 1 + arch/arm64/kernel/probes/Makefile | 1 + arch/arm64/kernel/probes/ftrace.c | 78 +++++++++++++++++++ 5 files changed, 82 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 4fae0464ddff..f9dd9dd91e0c 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 b1b4476ddb83..92b9882889ac 100644 --- a/arch/arm64/Kconfig +++ b/arch/arm64/Kconfig @@ -166,6 +166,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/include/asm/ftrace.h b/arch/arm64/include/asm/ftrace.h index 91fa4baa1a93..875aeb839654 100644 --- a/arch/arm64/include/asm/ftrace.h +++ b/arch/arm64/include/asm/ftrace.h @@ -20,6 +20,7 @@ /* The BL at the callsite's adjusted rec->ip */ #define MCOUNT_INSN_SIZE AARCH64_INSN_SIZE +#define FTRACE_IP_EXTENSION MCOUNT_INSN_SIZE #define FTRACE_PLT_IDX 0 #define FTRACE_REGS_PLT_IDX 1 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..0643aa2dacdb --- /dev/null +++ b/arch/arm64/kernel/probes/ftrace.c @@ -0,0 +1,78 @@ +// 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 + +/* + * In arm64 FTRACE_WITH_REGS implementation, we patch two nop instructions: + * the lr saver and bl ftrace-entry. Both these instructions are claimed + * by ftrace and we should allow probing on either instruction. + */ +int arch_check_ftrace_location(struct kprobe *p) +{ + if (ftrace_location((unsigned long)p->addr)) + p->flags |= KPROBE_FLAG_FTRACE; + return 0; +} + +/* 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) +{ + bool lr_saver = false; + struct kprobe *p; + struct kprobe_ctlblk *kcb; + + /* Preempt is disabled by ftrace */ + p = get_kprobe((kprobe_opcode_t *)ip); + if (!p) { + p = get_kprobe((kprobe_opcode_t *)(ip - MCOUNT_INSN_SIZE)); + if (unlikely(!p) || kprobe_disabled(p)) + return; + lr_saver = true; + } + + kcb = get_kprobe_ctlblk(); + if (kprobe_running()) { + kprobes_inc_nmissed_count(p); + } else { + unsigned long orig_ip = instruction_pointer(regs); + + if (lr_saver) + ip -= MCOUNT_INSN_SIZE; + instruction_pointer_set(regs, ip); + __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; +}