Received: by 2002:a25:8b12:0:0:0:0:0 with SMTP id i18csp515226ybl; Thu, 22 Aug 2019 00:13:15 -0700 (PDT) X-Google-Smtp-Source: APXvYqytfY2mhrKKMcCmw1OJf1LBHQKmtWy5BrjJK8vJw3v8lq2mwUlYYBW4E1nR6deZkSI6p0P9 X-Received: by 2002:a65:43c2:: with SMTP id n2mr32752732pgp.110.1566457994819; Thu, 22 Aug 2019 00:13:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1566457994; cv=none; d=google.com; s=arc-20160816; b=Oobiix/OEOsGUI+2n681YqpGItLbwmURecOzVsfKSwe9DmFEHVnTd8Rnucaib+kiL3 THvSoN47HCPO0iC6y2tZ5t6lPXaJTesFQQg8rRPYWiSBHzt1r0+Nvsp/elbHXNjfuJ6y bUvG2uOhI1MGl5Jy1t438R8qfQ/h4oCmBjR1yOcAEPyyxovuf+qDeQV9K/fzVHFYh7sJ wG6SGIg1/KDmTFYa8tX6LOf+wluWsQgqGSGmK4LMUycy4uUtnV1XQFvY14Hs/dBTb7d2 aNc4IzYER2iMl48/aGVRmJR4SPphsal48yysoVXzvN2jQk/8ztNNQ3V3FFATEd8NdEeI Y15g== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:message-id:content-transfer-encoding :user-agent:mime-version:in-reply-to:references:cc:to:subject:from :date; bh=rDpDA7aEuzBiggfUQXyjPaGAdVrMYXuLBQybnyGKt10=; b=s/PghGY3AFZvHYuDJrp/31/D2s2/HWQlC5LbIrOJRQQYX1ggwiSwDS1hJhKeLC5b79 c1YjQSv/T1A+2YPowFfVZRxM5ZxCuoKSblvNfaUyePZL61qSS3Ry3cyXdYPQpI3lL6Hk UAr4JqSyueSPfjIgZt5rZrxkSLWgt0hMZBSJYtFk4kzDihfAKjnpass3yvgYwFhAFw4J mPcGN8zWqIuBpDgECgVRvFg4XkyfMM24JMlqR2hRiEiOAhr1C82v9ZfytvB9okvx3Xv6 VNhPWRXVNKP3Kjx028wBS0o4N6qT95t3xE+COWR1AO8wFIS6pFaS1nC1C0sZa2a74BBR XGnw== ARC-Authentication-Results: i=1; mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id g14si18074704pfk.149.2019.08.22.00.13.00; Thu, 22 Aug 2019 00:13:14 -0700 (PDT) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=ibm.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729671AbfHVGyJ convert rfc822-to-8bit (ORCPT + 99 others); Thu, 22 Aug 2019 02:54:09 -0400 Received: from mx0a-001b2d01.pphosted.com ([148.163.156.1]:34596 "EHLO mx0a-001b2d01.pphosted.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726474AbfHVGyJ (ORCPT ); Thu, 22 Aug 2019 02:54:09 -0400 Received: from pps.filterd (m0098393.ppops.net [127.0.0.1]) by mx0a-001b2d01.pphosted.com (8.16.0.27/8.16.0.27) with SMTP id x7M6qovn051731 for ; Thu, 22 Aug 2019 02:54:08 -0400 Received: from e06smtp05.uk.ibm.com (e06smtp05.uk.ibm.com [195.75.94.101]) by mx0a-001b2d01.pphosted.com with ESMTP id 2uhmdfbf3s-1 (version=TLSv1.2 cipher=AES256-GCM-SHA384 bits=256 verify=NOT) for ; Thu, 22 Aug 2019 02:54:07 -0400 Received: from localhost by e06smtp05.uk.ibm.com with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted for from ; Thu, 22 Aug 2019 07:54:05 +0100 Received: from b06cxnps3074.portsmouth.uk.ibm.com (9.149.109.194) by e06smtp05.uk.ibm.com (192.168.101.135) with IBM ESMTP SMTP Gateway: Authorized Use Only! Violators will be prosecuted; (version=TLSv1/SSLv3 cipher=AES256-GCM-SHA384 bits=256/256) Thu, 22 Aug 2019 07:54:00 +0100 Received: from b06wcsmtp001.portsmouth.uk.ibm.com (b06wcsmtp001.portsmouth.uk.ibm.com [9.149.105.160]) by b06cxnps3074.portsmouth.uk.ibm.com (8.14.9/8.14.9/NCO v10.0) with ESMTP id x7M6rxBW49021104 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-GCM-SHA384 bits=256 verify=OK); Thu, 22 Aug 2019 06:53:59 GMT Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id 46BD8A4062; Thu, 22 Aug 2019 06:53:59 +0000 (GMT) Received: from b06wcsmtp001.portsmouth.uk.ibm.com (unknown [127.0.0.1]) by IMSVA (Postfix) with ESMTP id DBF21A405F; Thu, 22 Aug 2019 06:53:58 +0000 (GMT) Received: from localhost (unknown [9.199.32.226]) by b06wcsmtp001.portsmouth.uk.ibm.com (Postfix) with ESMTP; Thu, 22 Aug 2019 06:53:58 +0000 (GMT) Date: Thu, 22 Aug 2019 12:23:58 +0530 From: "Naveen N. Rao" Subject: Re: [PATCH v4] arm64: implement KPROBES_ON_FTRACE To: Catalin Marinas , Jonathan Corbet , Jisheng Zhang , Masami Hiramatsu , Will Deacon Cc: "linux-arm-kernel@lists.infradead.org" , "linux-doc@vger.kernel.org" , "linux-kernel@vger.kernel.org" , Mark Rutland , Ingo Molnar , Peter Zijlstra , Steven Rostedt , Thomas Gleixner References: <20190822113421.52920377@xhacker.debian> In-Reply-To: <20190822113421.52920377@xhacker.debian> MIME-Version: 1.0 User-Agent: astroid/0.15.0 (https://github.com/astroidmail/astroid) Content-Type: text/plain; charset=utf-8; format=flowed Content-Transfer-Encoding: 8BIT X-TM-AS-GCONF: 00 x-cbid: 19082206-0020-0000-0000-000003625D37 X-IBM-AV-DETECTION: SAVI=unused REMOTE=unused XFE=unused x-cbparentid: 19082206-0021-0000-0000-000021B796B9 Message-Id: <1566456155.27ojwy97ss.naveen@linux.ibm.com> X-Proofpoint-Virus-Version: vendor=fsecure engine=2.50.10434:,, definitions=2019-08-22_05:,, signatures=0 X-Proofpoint-Spam-Details: rule=outbound_notspam policy=outbound score=0 priorityscore=1501 malwarescore=0 suspectscore=0 phishscore=0 bulkscore=0 spamscore=0 clxscore=1015 lowpriorityscore=0 mlxscore=0 impostorscore=0 mlxlogscore=999 adultscore=0 classifier=spam adjust=0 reason=mlx scancount=1 engine=8.0.1-1906280000 definitions=main-1908220074 Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Jisheng Zhang wrote: > 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+0x4 [DISABLED][FTRACE] > > Signed-off-by: Jisheng Zhang This looks good to me. Except for a small confirmation below: Reviewed-by: Naveen N. Rao > --- > 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. > > Applied after arm64 FTRACE_WITH_REGS: > http://lists.infradead.org/pipermail/linux-arm-kernel/2019-August/674404.html > > Changes since v3: > - move kprobe_lookup_name() and arch_kprobe_on_func_entry to ftrace.c since > we only want to choose the ftrace entry for KPROBES_ON_FTRACE. > - only choose ftrace entry if (addr && !offset) > > Changes since v2: > - remove patch1, make it a single cleanup patch > - remove "This patch" in the change log > - implement arm64's kprobe_lookup_name() and arch_kprobe_on_func_entry instead > of patching the common kprobes code > > Changes since v1: > - make the kprobes/x86: use instruction_pointer and instruction_pointer_set > as patch1 > - add Masami's ACK to patch1 > - add some description about KPROBES_ON_FTRACE and why we need it on > arm64 > - correct the log before the patch > - remove the consolidation patch, make it as TODO > - only adjust kprobe's addr when KPROBE_FLAG_FTRACE is set > - if KPROBES_ON_FTRACE, ftrace_call_adjust() the kprobe's addr before > calling ftrace_location() > - update the kprobes-on-ftrace/arch-support.txt in doc > > > .../debug/kprobes-on-ftrace/arch-support.txt | 2 +- > arch/arm64/Kconfig | 1 + > arch/arm64/kernel/probes/Makefile | 1 + > arch/arm64/kernel/probes/ftrace.c | 84 +++++++++++++++++++ > 4 files changed, 87 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..5989c57660f3 > --- /dev/null > +++ b/arch/arm64/kernel/probes/ftrace.c > @@ -0,0 +1,84 @@ > +// 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 + 4 as breakpoint hit */ > + instruction_pointer_set(regs, ip + sizeof(kprobe_opcode_t)); Just want to make sure that you've confirmed that this is what happens with a regular trap/brk based kprobe on ARM64. The reason for setting the instruction pointer here is to ensure that it is set to the same value as would be set if there was a trap/brk instruction at the ftrace location. This ensures that the kprobe pre handler sees the same value regardless. Further changes to the instruction pointer are to achieve the same effect for kprobe post handlers. - Naveen