Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp5641269ybg; Tue, 22 Oct 2019 06:22:14 -0700 (PDT) X-Google-Smtp-Source: APXvYqxvLr15QBnRosiJWgreelLOBV/c3YhL3KhPcTUsQMKA87i2Vl8DCw47LCsQ1Tgt1jmq8hrp X-Received: by 2002:a17:906:c317:: with SMTP id s23mr28157382ejz.251.1571750534188; Tue, 22 Oct 2019 06:22:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571750534; cv=none; d=google.com; s=arc-20160816; b=Uc9/4lvbuTAgx+yLFhIUAgfSKAVRuNgfIkk6gbimxVPB9MKvhiUqwoPFDuLmK5NZxP y++sHHfgtleo9UttSyiDFP5Es5uzoDKyahVHReaITuVQHSCyw9IQQx9YLKx3gCUXQoHG 7sEMW2aV5OGJSRUkF16iVN0lZvz8Sloe9mxusHIA6ujcG5e2DTFS4VR2vyi8zjbKeaxa QfoGc1U8+x/1hEHDVnbDRkoLXKe1TPgYk8hUIxWnsj0atecouz7q6Gz8Yhm2wqvTFHQK Pi01udr3JlpV/cAUngUhaZCdkn9yxjftDSIQgYMxQ9QTclIIOS7C0usiuBuXSAEC+u4Q l0fg== 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; bh=IqDvf60y/sqP3x/xd857IfugrHfTmo5/P9sJE8a9nXg=; b=r1cfu64SPe0cF+aN824ylhrU3898vkf+7bbxW1vEt7Yk6FQ8s15qhtNfQV3lF1uD1+ V45oiwSz4FSEWB9/GcTlGCFIPAfJme+YYH+S9FNwziSaXDDOTwwuLi6eBMFtUVLVfhJa ssZBrQpmiih5mN9Aal34hZuHpRDYEv0RO+ncQuuhA3tzmabOusstZUgiOp/JKfX0GjTh 29ffTd3HplZlr5PsiLpfLzmykvL15ULgNfEY02iTjIGbIGFLQVRgsdRU/qU/DHKdsYGJ FIKIw0MS0jS9SZluKdXckNAIXUbuYJsjl8c5L/4o8eDZ2+lklv4x/9xPkhTSXcOPMpfK qaKQ== 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id jz12si10429200ejb.193.2019.10.22.06.21.48; Tue, 22 Oct 2019 06:22: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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S2387659AbfJVLUB (ORCPT + 99 others); Tue, 22 Oct 2019 07:20:01 -0400 Received: from mail.kernel.org ([198.145.29.99]:56844 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725788AbfJVLUB (ORCPT ); Tue, 22 Oct 2019 07:20:01 -0400 Received: from gandalf.local.home (cpe-66-24-58-225.stny.res.rr.com [66.24.58.225]) (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 D730320B7C; Tue, 22 Oct 2019 11:19:58 +0000 (UTC) Date: Tue, 22 Oct 2019 07:19:56 -0400 From: Steven Rostedt To: Alexei Starovoitov Cc: Peter Zijlstra , Daniel Bristot de Oliveira , LKML , X86 ML , Nadav Amit , Andy Lutomirski , Dave Hansen , Song Liu , Masami Hiramatsu Subject: Re: [PATCH 3/3] x86/ftrace: Use text_poke() Message-ID: <20191022071956.07e21543@gandalf.local.home> In-Reply-To: <20191022040532.fvpxcs74i4mn4rc6@ast-mbp.dhcp.thefacebook.com> References: <20191002182106.GC4643@worktop.programming.kicks-ass.net> <20191003181045.7fb1a5b3@gandalf.local.home> <20191004112237.GA19463@hirez.programming.kicks-ass.net> <20191004094228.5a5774fe@gandalf.local.home> <20191021204310.3c26f730@oasis.local.home> <20191021231630.49805757@oasis.local.home> <20191021231904.4b968dc1@oasis.local.home> <20191022040532.fvpxcs74i4mn4rc6@ast-mbp.dhcp.thefacebook.com> X-Mailer: Claws Mail 3.17.3 (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 On Mon, 21 Oct 2019 21:05:33 -0700 Alexei Starovoitov wrote: > On Mon, Oct 21, 2019 at 11:19:04PM -0400, Steven Rostedt wrote: > > On Mon, 21 Oct 2019 23:16:30 -0400 > > Steven Rostedt wrote: > > > > > > what bugs you're seeing? > > > > The IPI frequency that was mentioned in this thread or something else? > > > > I'm hacking ftrace+bpf stuff in the same spot and would like to > > > > base my work on the latest and greatest. > > > > I'm also going to be touching some of this code too, as I'm waiting for > > Peter's code to settle down. What are you touching? I'm going to be > > working on making the dyn_ftrace records smaller, and this is going to > > change the way the iterations work on modifying the code. > > I'm not touching dyn_ftrace. > Actually calling my stuff ftrace+bpf is probably not correct either. > I'm reusing code patching of nop into call that ftrace does. That's it. > Turned out I cannot use 99% of ftrace facilities. > ftrace_caller, ftrace_call, ftrace_ops_list_func and the whole ftrace api > with ip, parent_ip and pt_regs cannot be used for this part of the work. > bpf prog needs to access raw function arguments. To achieve that I'm You can do that today with the ftrace facility, just like live patching does. You register a ftrace_ops with the flag FTRACE_OPS_FL_IPMODIFY, and your func will set the regs->ip to your bpf handler. When the ftrace_ops->func returns, instead of going back to the called function, it can jump to your bpf_handler. You can create a shadow stack (like function graph tracer does) to save the return address for where you bpf handler needs to return to. As your bpf_handler needs raw access to the parameters, it may not even need the shadow stack because it should know the function it is reading the parameters from. If you still want the return address without the shadow stack, it wouldn't be hard to add another ftrace_ops flag, that allows the ftrace_ops to inject a return address to simulate a call function before it jumps to the modified IP. > generating code on the fly. Just like bpf jits do. > As soon as I have something reviewable I'll share it. > That's the stuff I mentioned to you at KR. > First nop of a function will be replaced with a call into bpf. > Very similar to what existing kprobe+bpf does, but faster and safer. > Second part of calling real ftrace from bpf is on todo list. Having two different infrastructures modifying the first nop is going to cause a huge nightmare to maintain. This is why live patching didn't do it. I strongly suggested that you do not have bpf have its own infrastructure. -- Steve