Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp1438624ybh; Thu, 23 Jul 2020 08:56:32 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw7FPIlcGdN6r+h/QYCxwEoRvltu/gIspfiG+UPkjDzRQjZN5dzWTB4i8mYGGhvkmUpyQV5 X-Received: by 2002:aa7:dd14:: with SMTP id i20mr4939475edv.41.1595519792407; Thu, 23 Jul 2020 08:56:32 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595519792; cv=none; d=google.com; s=arc-20160816; b=hmsBIvqvehi/AVDuKYIRlq0QXJuxtcpWxyf/ceve3kuKJ/9+WbtYA9J8Y687CHHZ48 IR/DMZdvIerA3t8YZNYOmZNJqtaxIQTt/MxrSGA14RLCihOlrldh/L+u9fv+igcneyJj X2eXi8ZS4uzAsUKfg9ASyhU7ELyx00t1FzTAbitPhS4Fhpa24t8kxd9qFUcLJPtwns2j K7eFHsrlVtgpWgglE3DBij/zkKvIuxoWyjc9+4xWnE1Rer8uFCOJpVun2e72+zhySbfP KVHLkpmEsoZslHKSHBMs17ct9RxGSbztUug84ve5FXDkHyI00DTuM6u71/JKfdn0mDNT lqxA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:subject:cc:to:from:date :dkim-signature; bh=wYBYVJYdKxA4V0f1lieaBPF0iAtjh7g4pVE/NqZDMTo=; b=yziKy44li3Cnk0zo7eT2NAUf7tnaBmCEl1VlY7w8S1kFYZoZVgltYsO1t6wzAY4rKo 849Wap97BZIFVJ8l9fyddm97EuM85EWSJxvaOvnQnFhC1uCnhyub9SN6z9Kw1JO8Jf/h SNuCBY2oeP7TUTjqiqf3pssIV3UaUj79uINHaGOdHPHifJAyBsT944pON37xu8AMGuQS st3HWO54cfcvByChqpUPHbfnyzzBM5wHW5sVPIAsbGFaPo6W3bfsg+2ox6Mqh8AMXaDI g1tZqVs4oZcwxJLu5mwhY2SjwvGBDp7FiPYs2jL7u9t9+up9sstIx/bQQ0x3QVfdChxQ CY+g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0+JgSJk1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id u25si2169313edq.436.2020.07.23.08.56.09; Thu, 23 Jul 2020 08:56:32 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=0+JgSJk1; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729014AbgGWPzh (ORCPT + 99 others); Thu, 23 Jul 2020 11:55:37 -0400 Received: from mail.kernel.org ([198.145.29.99]:33864 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726761AbgGWPzh (ORCPT ); Thu, 23 Jul 2020 11:55:37 -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 AD83120674; Thu, 23 Jul 2020 15:55:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595519736; bh=794oAZiy8ioLny+/Vr1tNGrLTY249LqhcFj6aS5p5q0=; h=Date:From:To:Cc:Subject:In-Reply-To:References:From; b=0+JgSJk1dXhhIMv0nAOS2nDA1d724WZmuJsOZuKsCI2bSawYdcMTMe1MLG+C72u8O s2l0ecLkuJd3yFX8AteP06ydgbYdprPLGMKL/gCsuGvbMHaCukAgG5ek/uk4jRDcMF kRmvO0NowMo++AH6lrhBzjfcuHUncWxykhGvW/gQ= Date: Fri, 24 Jul 2020 00:55:31 +0900 From: Masami Hiramatsu To: Guo Ren Cc: Palmer Dabbelt , Paul Walmsley , Oleg Nesterov , linux-riscv , Linux Kernel Mailing List , Anup Patel , linux-csky@vger.kernel.org, Greentime Hu , Zong Li , Patrick =?UTF-8?B?U3TDpGhsaW4=?= , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Guo Ren , Pekka Enberg Subject: Re: [PATCH v3 6/7] riscv: Add KPROBES_ON_FTRACE supported Message-Id: <20200724005531.e1fe3c7f024886a1a04e16eb@kernel.org> In-Reply-To: References: <1594683562-68149-1-git-send-email-guoren@kernel.org> <1594683562-68149-7-git-send-email-guoren@kernel.org> <20200714203757.512ce7fb5fa61a88b1dbb2f3@kernel.org> <20200721222701.3074315f6a9f6c42c5963f40@kernel.org> X-Mailer: Sylpheed 3.7.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 22 Jul 2020 16:39:53 +0800 Guo Ren wrote: > Hi Masami, > > On Tue, Jul 21, 2020 at 9:27 PM Masami Hiramatsu wrote: > > > > On Wed, 15 Jul 2020 00:24:54 +0800 > > Guo Ren wrote: > > > > > Thx Masami, > > > > > > On Tue, Jul 14, 2020 at 7:38 PM Masami Hiramatsu wrote: > > > > > > > > On Mon, 13 Jul 2020 23:39:21 +0000 > > > > guoren@kernel.org wrote: > > > > > > > > > From: Guo Ren > > > > > > > > > > This patch adds support for kprobes on ftrace call sites to avoids > > > > > much of the overhead with regular kprobes. Try it with simple > > > > > steps: > > > > > > > > > > 1. Get _do_fork ftrace call site. > > > > > Dump of assembler code for function _do_fork: > > > > > 0xffffffe00020af64 <+0>: addi sp,sp,-128 > > > > > 0xffffffe00020af66 <+2>: sd s0,112(sp) > > > > > 0xffffffe00020af68 <+4>: sd ra,120(sp) > > > > > 0xffffffe00020af6a <+6>: addi s0,sp,128 > > > > > 0xffffffe00020af6c <+8>: sd s1,104(sp) > > > > > 0xffffffe00020af6e <+10>: sd s2,96(sp) > > > > > 0xffffffe00020af70 <+12>: sd s3,88(sp) > > > > > 0xffffffe00020af72 <+14>: sd s4,80(sp) > > > > > 0xffffffe00020af74 <+16>: sd s5,72(sp) > > > > > 0xffffffe00020af76 <+18>: sd s6,64(sp) > > > > > 0xffffffe00020af78 <+20>: sd s7,56(sp) > > > > > 0xffffffe00020af7a <+22>: mv s4,a0 > > > > > 0xffffffe00020af7c <+24>: mv a0,ra > > > > > 0xffffffe00020af7e <+26>: nop <<<<<<<< here! > > > > > 0xffffffe00020af82 <+30>: nop > > > > > 0xffffffe00020af86 <+34>: ld s3,0(s4) > > > > > > > > > > 2. Set _do_fork+26 as the kprobe. > > > > > echo 'p:myprobe _do_fork+26 dfd=%a0 filename=%a1 flags=%a2 mode=+4($stack)' > /sys/kernel/debug/tracing/kprobe_events > > > > > echo 1 > /sys/kernel/debug/tracing/events/kprobes/enable > > > > > cat /sys/kernel/debug/tracing/trace > > > > > tracer: nop > > > > > > > > > > entries-in-buffer/entries-written: 3/3 #P:1 > > > > > > > > > > _-----=> irqs-off > > > > > / _----=> need-resched > > > > > | / _---=> hardirq/softirq > > > > > || / _--=> preempt-depth > > > > > ||| / delay > > > > > TASK-PID CPU# |||| TIMESTAMP FUNCTION > > > > > | | | |||| | | > > > > > sh-87 [000] .... 551.557031: myprobe: (_do_fork+0x1a/0x2e6) dfd=0xffffffe00020af7e filename=0xffffffe00020b34e flags=0xffffffe00101e7c0 mode=0x20af86ffffffe0 > > > > > > > > > > cat /sys/kernel/debug/kprobes/list > > > > > ffffffe00020af7e k _do_fork+0x1a [FTRACE] > > > > > ^^^^^^ > > > > > > > > Hmm, this seems fentry is not supported on RISC-V yet. But anyway, > > > > it will be useful for users (if they can find the offset). > > > > > > Seems only x86 & ⬆️90 use fentry,can you elaborate more about fentry's > > > benefit and how the user could set kprobe on ftrace call site without > > > disassemble? > > > > On x86, the fentry replaces the mcount with just one call instruction, without > > saving any arguments. This means all probes which are puts on the address of > > target symbol, are automatically using ftrace. IOW, all probes on _do_fork+0 > > will use ftrace. We don't need any disassembling. > > > > I think if RISC-V already support "-fpatchable-function-entry=2" option on > > GCC, you can easily enable it as same as arm64. See https://lkml.org/lkml/2019/6/18/648 > the link is: > [PATCH 0/7] powerpc/ftrace: Patch out -mprofile-kernel instructions Oops, sorry. https://lore.kernel.org/linux-arm-kernel/20191225172625.69811b3e@xhacker.debian/ this should be the right one. -- Masami Hiramatsu