Received: by 2002:a25:e74b:0:0:0:0:0 with SMTP id e72csp517868ybh; Wed, 22 Jul 2020 06:34:47 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyZQ++wMNyo4apwsyofqjWLXRXDdrZhJt2JzItNJKgKj1tzkq0vrW8cSskVcSDOZWUiMPJq X-Received: by 2002:a17:906:9348:: with SMTP id p8mr31932806ejw.467.1595424887462; Wed, 22 Jul 2020 06:34:47 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1595424887; cv=none; d=google.com; s=arc-20160816; b=ofc8nN0QoRKndAPovcU826MtHIqqK51X8tsB498WTK7v+2Cp4N10ylC3KuzxMFsqfv MCN0MQcGA2whmup04xctJ8Qa6UhdyE1jRlMZAQQpyDL2nSms8AHgN6ZTSnibWE7dIi6S DHo0VhiOE1F/TqqA95qa7ikv4FZWgnizgtUCVkCCv5+yaz+Mf5rxVn2/0a8FHD+pSWN8 zloL3rZROJvkVCJdQRGtawD9nQI4Snw7leY6mBOLOlRxTyTNJuBtEGnYrviV8jQc9ve2 QVDMxCdidmLafYU/iSVt/UlkXnDtgqqxwW6eyrxv5gF8B/TQBg7uWilI9sSmPWkSoBvx uYsA== 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:cc:to:subject :message-id:date:from:in-reply-to:references:mime-version :dkim-signature; bh=h5cDquLS9pifn0JbLC8pLhyNjTk/+TgpJLpDnLdX3vo=; b=Ane79czPnlCxuohLKELyCbs6Zyzq3yEuyRi0b82d9+4d9sT3IHUtgETJZfxBbGGQkl woytXsC+nLKXMJg4QQnbTvQtBiXokSqwgnxpq6KncQAclpNTWqfAyjRvanL04xZ79neg bl9Rkv1nrQe8qqDwR209bX9VSI7a1BGcsjHAwH57ackhg4kZgrdfGpI7TdA6gZV4boky uITsj9wc54eMRmo0+izlrFEEYZmdABn3Jng1lMB+R3v6OzA3mZndTakdp7aXR6KNmgcH eEPOejYxBXTsEyMYiYIUvjw+ltXFM1psM+xgM6VDY74CKjWWsHpRVxUDbB5MKnPujX+I xjAg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=default header.b=qtqVsywT; 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 mh8si4158ejb.245.2020.07.22.06.34.24; Wed, 22 Jul 2020 06:34:47 -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=qtqVsywT; 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 S1732241AbgGVNbg (ORCPT + 99 others); Wed, 22 Jul 2020 09:31:36 -0400 Received: from mail.kernel.org ([198.145.29.99]:58504 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726146AbgGVNbe (ORCPT ); Wed, 22 Jul 2020 09:31:34 -0400 Received: from mail-lj1-f171.google.com (mail-lj1-f171.google.com [209.85.208.171]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPSA id CAB11207BB; Wed, 22 Jul 2020 13:31:33 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=default; t=1595424694; bh=G+K3d514kcxDDUU/TieFP3V0nSBRnKLAgwKlg3nKpOE=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=qtqVsywTdyKY0aLtGD7JuZ+qcoKUwI4hl8trE9CPPMhV3qlgTpMTYLvs5Y0jeTGlC k0g/7b8jeMzwqCY/GM+3WrGj7wo7qTagwHXLA/K2A/8jK92j0czE+TPYj2Q5QECoy6 NWp9gVuH6gKeb6Zr8H5ZHawpEr1CELbE85dKoCa0= Received: by mail-lj1-f171.google.com with SMTP id j11so2493100ljo.7; Wed, 22 Jul 2020 06:31:33 -0700 (PDT) X-Gm-Message-State: AOAM5330qKK8C5u0YX2Vy55LFXtHLxB1M63VSE08R/c64OWnfIG14fzw Wh2LHfI8cZr5Qu0OXm2Tgz4ADQKb976rF2TgHLs= X-Received: by 2002:a2e:b0ed:: with SMTP id h13mr14060325ljl.250.1595424692019; Wed, 22 Jul 2020 06:31:32 -0700 (PDT) MIME-Version: 1.0 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> In-Reply-To: <20200721222701.3074315f6a9f6c42c5963f40@kernel.org> From: Guo Ren Date: Wed, 22 Jul 2020 21:31:20 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v3 6/7] riscv: Add KPROBES_ON_FTRACE supported To: Masami Hiramatsu Cc: Palmer Dabbelt , Paul Walmsley , Oleg Nesterov , linux-riscv , Linux Kernel Mailing List , Anup Patel , linux-csky@vger.kernel.org, Greentime Hu , Zong Li , =?UTF-8?Q?Patrick_St=C3=A4hlin?= , =?UTF-8?B?QmrDtnJuIFTDtnBlbA==?= , Guo Ren , Pekka Enberg Content-Type: text/plain; charset="UTF-8" Content-Transfer-Encoding: quoted-printable Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Hi Masami, Current riscv ftrace_caller utilize fp(s0) - 8 in stack to get ra of function, eg: foo: 2bb0: 7119 addi sp,sp,-128 2bb2: f8a2 sd s0,112(sp) 2bb4: fc86 sd ra,120(sp) ... 2bc4: 0100 addi s0,sp,128 ... 0000000000002bca <.LVL828>: 2bca: 00000097 auipc ra,0x0 2bce: 000080e7 jalr ra # 2bca <.LVL828> //_mcou= nt So just put two nops before prologue of function isn't enough, because riscv don't like arm64 which could use x9-x18 reserved regs to pass ra(x30). | mov x9, x30 | bl If the benefit is just making a kprobe on function symbol address to prevent disassembling, I'll delay this feature. I also have a look at HAVE_FENTRY & HAVE_NOP_MCOUNT. Seems it just avoid using scripts/recordmcount.pl script and directly generate nops for _mcount. It's different from -fpatchable-function-entry=3D2 which generating nops before function prologue in arm64, isn't it? On Tue, Jul 21, 2020 at 9:27 PM Masami Hiramatsu wrot= e: > > 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=3D%a0 filename=3D%a1 flags=3D%a2 = mode=3D+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 > > > > > > > > _-----=3D> irqs-off > > > > / _----=3D> need-resched > > > > | / _---=3D> hardirq/softirq > > > > || / _--=3D> preempt-depth > > > > ||| / delay > > > > TASK-PID CPU# |||| TIMESTAMP FUNCTION > > > > | | | |||| | | > > > > sh-87 [000] .... 551.557031: myprobe: (_do_fork+= 0x1a/0x2e6) dfd=3D0xffffffe00020af7e filename=3D0xffffffe00020b34e flags=3D= 0xffffffe00101e7c0 mode=3D0x20af86ffffffe0 > > > > > > > > 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 & =E2=AC=86=EF=B8=8F90 use fentry=EF=BC=8Ccan you elabor= ate 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, wi= thout > 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_for= k+0 > will use ftrace. We don't need any disassembling. > > I think if RISC-V already support "-fpatchable-function-entry=3D2" option= on > GCC, you can easily enable it as same as arm64. See https://lkml.org/lkml= /2019/6/18/648 > > Thank you, > > -- > Masami Hiramatsu --=20 Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/