From mboxrd@z Thu Jan 1 00:00:00 1970 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=-7.1 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY, SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED autolearn=ham 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 7450DC3A5A0 for ; Tue, 20 Aug 2019 00:07:44 +0000 (UTC) Received: from vger.kernel.org (vger.kernel.org [209.132.180.67]) by mail.kernel.org (Postfix) with ESMTP id 4491222CE8 for ; Tue, 20 Aug 2019 00:07:44 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566259664; bh=mRNGqagv3FLOfbEDFWbY21Sn764t8uAC5ZUxJM6X+Ag=; h=Date:From:To:Cc:Subject:In-Reply-To:References:List-ID:From; b=OXwXMV4OQSiBccnf/TEMZkGCkDjm3Aip64JTMWi4gj8PZSKcjwyu9GMdDgF0r5kQ2 t2egT+iThcEiWmcswC/7JsQmYEfbUlg1aWauxI83xf+RNhq23aUIWCwq3UR/tPKXFi AV6Rdvqlq0akm+By3uzcdIbgxsOe8STB8SGItAy8= Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728704AbfHTAHm (ORCPT ); Mon, 19 Aug 2019 20:07:42 -0400 Received: from mail.kernel.org ([198.145.29.99]:37630 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728554AbfHTAHm (ORCPT ); Mon, 19 Aug 2019 20:07:42 -0400 Received: from devnote2 (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0AB462087E; Tue, 20 Aug 2019 00:07:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566259661; bh=mRNGqagv3FLOfbEDFWbY21Sn764t8uAC5ZUxJM6X+Ag=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ljj/+BvVaFfJsr8EJP7pRhxXV5WOosE2S5EjgFFZL5EWJA+IUA4fRpKrvE+zIPWi8 40VK1xyQ/1ub/fOJkjYEuAandPATqqA23MtQY7IdbMWQvwMS4mqRm15nNVJsET9Y7u qJIi+4w0pTk/PpkAoGYxQNX81kg78oZaIVSD3lX8= Date: Tue, 20 Aug 2019 09:07:35 +0900 From: Masami Hiramatsu To: Jisheng Zhang Cc: Catalin Marinas , Will Deacon , Thomas Gleixner , Ingo Molnar , Borislav Petkov , "H. Peter Anvin" , "David S. Miller" , Anil S Keshavamurthy , "Naveen N. Rao" , Steven Rostedt , "x86@kernel.org" , "linux-arm-kernel@lists.infradead.org" , "linux-kernel@vger.kernel.org" Subject: Re: [PATCH 3/4] kprobes: move kprobe_ftrace_handler() from x86 and make it weak Message-Id: <20190820090735.a55e7d0b685adecf68fdb55b@kernel.org> In-Reply-To: <20190819192628.5f550074@xhacker.debian> References: <20190819192422.5ed79702@xhacker.debian> <20190819192628.5f550074@xhacker.debian> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Jisheng, On Mon, 19 Aug 2019 11:37:32 +0000 Jisheng Zhang wrote: > This code could be reused. So move it from x86 to common code. Yes, it can be among some arch, but at first, please make your architecture implementation. After making sure that is enough stable, we will optimize (consolidate) the code. For example, > - /* Kprobe handler expects regs->ip = ip + 1 as breakpoint hit */ > - instruction_pointer_set(regs, ip + sizeof(kprobe_opcode_t)); This may depend on arch implementation of kprobes. Could you make a copy and update comments on arm64? Thank you, > > Signed-off-by: Jisheng Zhang > --- > arch/x86/kernel/kprobes/ftrace.c | 44 -------------------------------- > kernel/kprobes.c | 44 ++++++++++++++++++++++++++++++++ > 2 files changed, 44 insertions(+), 44 deletions(-) > > diff --git a/arch/x86/kernel/kprobes/ftrace.c b/arch/x86/kernel/kprobes/ftrace.c > index c2ad0b9259ca..91ae1e3e65f7 100644 > --- a/arch/x86/kernel/kprobes/ftrace.c > +++ b/arch/x86/kernel/kprobes/ftrace.c > @@ -12,50 +12,6 @@ > > #include "common.h" > > -/* 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->ip = ip + 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->ip) > - * as if there is a 5byte 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->ip. 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.insn = NULL; > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > index f8400753a8a9..479148ee1822 100644 > --- a/kernel/kprobes.c > +++ b/kernel/kprobes.c > @@ -960,6 +960,50 @@ static struct kprobe *alloc_aggr_kprobe(struct kprobe *p) > #endif /* CONFIG_OPTPROBES */ > > #ifdef CONFIG_KPROBES_ON_FTRACE > +/* Ftrace callback handler for kprobes -- called under preepmt disabed */ > +void __weak 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->ip = ip + 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->ip) > + * as if there is a 5byte 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->ip. We have to > + * skip emulating post_handler. > + */ > + __this_cpu_write(current_kprobe, NULL); > + } > +} > +NOKPROBE_SYMBOL(kprobe_ftrace_handler); > + > static struct ftrace_ops kprobe_ftrace_ops __read_mostly = { > .func = kprobe_ftrace_handler, > .flags = FTRACE_OPS_FL_SAVE_REGS | FTRACE_OPS_FL_IPMODIFY, > -- > 2.23.0.rc1 > -- Masami Hiramatsu From mboxrd@z Thu Jan 1 00:00:00 1970 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=-7.0 required=3.0 tests=DKIMWL_WL_HIGH,DKIM_SIGNED, DKIM_VALID,INCLUDES_PATCH,MAILING_LIST_MULTI,SIGNED_OFF_BY,SPF_HELO_NONE, SPF_PASS,URIBL_BLOCKED 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 A530CC3A5A1 for ; Tue, 20 Aug 2019 00:07:45 +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 7832922CE8 for ; Tue, 20 Aug 2019 00:07:45 +0000 (UTC) Authentication-Results: mail.kernel.org; dkim=pass (2048-bit key) header.d=lists.infradead.org header.i=@lists.infradead.org header.b="HtjBJ4g4"; dkim=fail reason="signature verification failed" (1024-bit key) header.d=kernel.org header.i=@kernel.org header.b="ljj/+BvV" DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org 7832922CE8 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=kernel.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.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:References:In-Reply-To: Message-Id:Subject:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=fSwgw/9xTBK6kdB5Nab3okChDVwITBxVV5f9x5EMpSU=; b=HtjBJ4g4sO6EWa 8Sta5XUE/d63TcwWuTXLWWfopp3EMR2jfnOUOSfEONxXU5HoA4a3qamHbTKYiWUNtvGGBcHPLA/Dl M8zf6vEokeT962CmD3nyx9/f+2NBSzCNFbrOJhFIagL2m7S+ZqNoQQ/KAPmNO42ffhPCauOsQtl7L rXXk+e/x7Z//c6N5d8SYCQcxOnvk5koMsytA0CySS3qmX8w/eTpGSWf5AKNsQqdk6rpKc2h8Hv1ee Y+O5E/S0JBnFlJDuJ4NpgveiIL/IfAQdPdyg/WPCKr45EZEG5eZldEQixK8vrc9ol6L9yRslfuKxX fBOox88oCvADsb9lb02A==; 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 1hzrgf-0002th-4P; Tue, 20 Aug 2019 00:07:45 +0000 Received: from mail.kernel.org ([198.145.29.99]) by bombadil.infradead.org with esmtps (Exim 4.92 #3 (Red Hat Linux)) id 1hzrgb-0002tN-Au for linux-arm-kernel@lists.infradead.org; Tue, 20 Aug 2019 00:07:42 +0000 Received: from devnote2 (NE2965lan1.rev.em-net.ne.jp [210.141.244.193]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id 0AB462087E; Tue, 20 Aug 2019 00:07:37 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1566259661; bh=mRNGqagv3FLOfbEDFWbY21Sn764t8uAC5ZUxJM6X+Ag=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=ljj/+BvVaFfJsr8EJP7pRhxXV5WOosE2S5EjgFFZL5EWJA+IUA4fRpKrvE+zIPWi8 40VK1xyQ/1ub/fOJkjYEuAandPATqqA23MtQY7IdbMWQvwMS4mqRm15nNVJsET9Y7u qJIi+4w0pTk/PpkAoGYxQNX81kg78oZaIVSD3lX8= Date: Tue, 20 Aug 2019 09:07:35 +0900 From: Masami Hiramatsu To: Jisheng Zhang Subject: Re: [PATCH 3/4] kprobes: move kprobe_ftrace_handler() from x86 and make it weak Message-Id: <20190820090735.a55e7d0b685adecf68fdb55b@kernel.org> In-Reply-To: <20190819192628.5f550074@xhacker.debian> References: <20190819192422.5ed79702@xhacker.debian> <20190819192628.5f550074@xhacker.debian> X-Mailer: Sylpheed 3.5.1 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20190819_170741_418518_45799DDE X-CRM114-Status: GOOD ( 20.79 ) 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: Catalin Marinas , "x86@kernel.org" , "linux-kernel@vger.kernel.org" , Anil S Keshavamurthy , Ingo Molnar , Borislav Petkov , Steven Rostedt , "H. Peter Anvin" , "Naveen N. Rao" , Thomas Gleixner , Will Deacon , "David S. Miller" , "linux-arm-kernel@lists.infradead.org" Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+infradead-linux-arm-kernel=archiver.kernel.org@lists.infradead.org Hi Jisheng, On Mon, 19 Aug 2019 11:37:32 +0000 Jisheng Zhang wrote: > This code could be reused. So move it from x86 to common code. Yes, it can be among some arch, but at first, please make your architecture implementation. After making sure that is enough stable, we will optimize (consolidate) the code. For example, > - /* Kprobe handler expects regs->ip = ip + 1 as breakpoint hit */ > - instruction_pointer_set(regs, ip + sizeof(kprobe_opcode_t)); This may depend on arch implementation of kprobes. Could you make a copy and update comments on arm64? Thank you, > > Signed-off-by: Jisheng Zhang > --- > arch/x86/kernel/kprobes/ftrace.c | 44 -------------------------------- > kernel/kprobes.c | 44 ++++++++++++++++++++++++++++++++ > 2 files changed, 44 insertions(+), 44 deletions(-) > > diff --git a/arch/x86/kernel/kprobes/ftrace.c b/arch/x86/kernel/kprobes/ftrace.c > index c2ad0b9259ca..91ae1e3e65f7 100644 > --- a/arch/x86/kernel/kprobes/ftrace.c > +++ b/arch/x86/kernel/kprobes/ftrace.c > @@ -12,50 +12,6 @@ > > #include "common.h" > > -/* 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->ip = ip + 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->ip) > - * as if there is a 5byte 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->ip. 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.insn = NULL; > diff --git a/kernel/kprobes.c b/kernel/kprobes.c > index f8400753a8a9..479148ee1822 100644 > --- a/kernel/kprobes.c > +++ b/kernel/kprobes.c > @@ -960,6 +960,50 @@ static struct kprobe *alloc_aggr_kprobe(struct kprobe *p) > #endif /* CONFIG_OPTPROBES */ > > #ifdef CONFIG_KPROBES_ON_FTRACE > +/* Ftrace callback handler for kprobes -- called under preepmt disabed */ > +void __weak 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->ip = ip + 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->ip) > + * as if there is a 5byte 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->ip. We have to > + * skip emulating post_handler. > + */ > + __this_cpu_write(current_kprobe, NULL); > + } > +} > +NOKPROBE_SYMBOL(kprobe_ftrace_handler); > + > static struct ftrace_ops kprobe_ftrace_ops __read_mostly = { > .func = kprobe_ftrace_handler, > .flags = FTRACE_OPS_FL_SAVE_REGS | FTRACE_OPS_FL_IPMODIFY, > -- > 2.23.0.rc1 > -- Masami Hiramatsu _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel