Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp127011ybg; Tue, 22 Oct 2019 17:21:44 -0700 (PDT) X-Google-Smtp-Source: APXvYqwiaDslmdciVslp06f8xXFD+LqufnYCTyOwqow1iYYY2tl+uSqh13KSh05zMBZ0VrRdWWWL X-Received: by 2002:a05:6402:149a:: with SMTP id e26mr34106156edv.123.1571790103953; Tue, 22 Oct 2019 17:21:43 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571790103; cv=none; d=google.com; s=arc-20160816; b=kuwR5xTGggISn5dqC6kA55E6ZKRyJEc1PnMgGTZkw4NIYJKQk20a4WolfpBKKmcnXI Nydj4cNuqcY1AXH5wgpHG1RImewvImDn8Aw/EIl/9GGTBEiAelTimyrlBM5CLRtNj9TS hej+3AHOp4LKl3Ioo5xg42mz4emHW5O6FhFUGOM2/1vj5fwDiFttJBdzJZe7LtTRtUy/ Pz5SJlX9GbNG74RkFESh8jwT/qS2DK9qhF41nQ425DH+8wqWLJ7YvFncCEBMSlVouhBV RGL4GeLDhmQje0mcdHR5zxKTmqEdnn53/D0kGknq2WDaf4mMF+H1gj1WESCIui12Et9Q uYLQ== 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=dfe3dNVX+qVJx+9pTrOCW8N+K7QzPstLlml2KZgoY8k=; b=yym6+NuSVF+hwS+Zgrlq5AcfNzsi6VZ1Jfz+AR/hMyYaMGmnnt8ur0/GDAN7d0+6lr ChS4ZpmM5D6TiwSQEggKqdnmh7I/q0904/3SO9oHfJxqqkZipB4gL/AuoaVSsuKxA4ax 6MEEr9o7Uy3JWHjdOfn31c9gEicDkq+PI0CTlkI+wznFYGfrFUL/8B39DUQC+Q0fn1fF OgooZzLSQWNYSVcl9TarWpWy5/ajlFWC+sPMcW6iSUD+auJ9wlt8Fpk9FhLUQfdcE232 q2CgrgBxbUx4I1upVIcUcV4Q1gxhIIT88bJF/weLI+cg5h5aVorZauzkv/ekZMNKQrHI 699Q== 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 n3si15977600edc.151.2019.10.22.17.21.20; Tue, 22 Oct 2019 17:21:43 -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 S1732582AbfJVXVf convert rfc822-to-8bit (ORCPT + 99 others); Tue, 22 Oct 2019 19:21:35 -0400 Received: from mail.kernel.org ([198.145.29.99]:42770 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728081AbfJVXVf (ORCPT ); Tue, 22 Oct 2019 19:21:35 -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 E93AE206C2; Tue, 22 Oct 2019 23:21:33 +0000 (UTC) Date: Tue, 22 Oct 2019 19:21:32 -0400 From: Steven Rostedt To: Andy Lutomirski Cc: Alexei Starovoitov , 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: <20191022192132.22cc15b5@gandalf.local.home> In-Reply-To: <7364B113-DD65-423D-BED3-FF90C4DF8334@amacapital.net> References: <20191022215841.2qsmhd6vxi4mwade@ast-mbp.dhcp.thefacebook.com> <7364B113-DD65-423D-BED3-FF90C4DF8334@amacapital.net> 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=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 Tue, 22 Oct 2019 15:45:26 -0700 Andy Lutomirski wrote: > >> On Oct 22, 2019, at 2:58 PM, Alexei Starovoitov wrote: > >> > >> On Tue, Oct 22, 2019 at 05:04:30PM -0400, Steven Rostedt wrote: > >> I gave a solution for this. And that is to add another flag to allow > >> for just the minimum to change the ip. And we can even add another flag > >> to allow for changing the stack if needed (to emulate a call with the > >> same parameters). > > > > your solution is to reduce the overhead. > > my solution is to remove it competely. See the difference? > > > >> By doing this work, live kernel patching will also benefit. Because it > >> is also dealing with the unnecessary overhead of saving regs. > >> And we could possibly even have kprobes benefit from this if a kprobe > >> doesn't need full regs. > > > > Neither of two statements are true. The per-function generated trampoline > > I'm talking about is bpf specific. For a function with two arguments it's just: > > push rbp > > mov rbp, rsp > > push rdi > > push rsi > > lea rdi,[rbp-0x10] > > call jited_bpf_prog > > pop rsi > > pop rdi > > leave > > ret > > Why are you saving rsi? You said upthread that you’re saving the > args, but rsi is already available in rsi. The above is for two parameters, and is being called before the function with those two parameters. The jited_bpf_prog will be called with those two parameters as well, but it may also clobber them. Then we need to restore those two parameters before calling the original function. > > Just how custom is this bpf program? It seems to clobber no regs > (except args), and it doesn’t return anything. Is it entirely > specific to the probed function? If so, why not just call it > directly? It's injecting the jited_bpf_prog to be called when the probed function is called, with the same parameters as the probed function. my_probed_function call trampoline trampoline save parameters call jited_bpf_prog (with same parameters) restore paremeters ret Jumps back to the my_probed_function, where my_probed_function is clueless it was just interrupted. No need to save any clobbered registers but the parameters, as the jited_bpf_prog needs to save any registers that it clobbers just like the my_probed_function saves its. -- Steve