Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp124688ybg; Tue, 22 Oct 2019 17:18:57 -0700 (PDT) X-Google-Smtp-Source: APXvYqz6VEGy9N0tWE4pniHGwOgZH/IlN1M+g9lsTUFF0CxCvw7KeRZpFYvVGVHi/AVt/Xjp71rJ X-Received: by 2002:a50:c90d:: with SMTP id o13mr34130034edh.85.1571789937573; Tue, 22 Oct 2019 17:18:57 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571789937; cv=none; d=google.com; s=arc-20160816; b=euzel5IhKMkJ3XtXupLvuHN0bFUyhyIKLWQ/1l9hOjkW0mMXFJmJR1+LN+2ifcS/Fs vDQSRndwMZO0F7u0DLNXf/dLHS6PJy1OnB0qeSZJ8YTSMzbovR7VmJVOqYCA6QstJ9Ru EDViW9xItXt7Y4rBvIISkYFb9NucCp0tIIHFqB1oC/IqV7IRmIC0UKeG/+aBmJN9Cybo 5CWwRD89xgztGvNAMf8PwG6txTOKgqRWvAMOdEqMiT2y4VUEceKNP0ckekYN3bTiHOTH o+pYNQPWeWx7kC+malgkObnl+sZN1RDFm5w9S1CaLK+E7jNwqZ//L5M/ge5FCttzI8Nr Hfww== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:references:in-reply-to:subject :message-id:date:mime-version:from:content-transfer-encoding :dkim-signature; bh=7aR+uSzeMahVa2OPNUR1feGVGkqBz5tWi+pFrnNsLQY=; b=wmVnR5upQRaD054uaXGvFsfgbss8TWp02x74g6275agLz5NRRQPDtzFwte98fabVd3 MRfWhgv3ExNcuUMl4q4icqw6E6q5B1mUuydzwTSRgjW4m7feGRgni8yB8V9sHIWpy1tF c5diRjYqo3nl6ieuc56qn1MpbGWcmne/roaq+BaG9z3MZHZVRReSJhQnJJSAHOmJj6E+ MRsGb4aBmAWPltF2CKGyqVTI54505Lx32qth3mJBVvUx1yYD6ZfZbbrr8gVpAD05mugL Ekqzi1wbsBbP4296R0eGjvwbGJolcMfUYhF8KX0y4Zo5DcJsBVdYzFQxWya9hnJwyshU PugA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=HidD9NII; 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 m5si1850043ejr.417.2019.10.22.17.18.32; Tue, 22 Oct 2019 17:18:57 -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; dkim=pass header.i=@amacapital-net.20150623.gappssmtp.com header.s=20150623 header.b=HidD9NII; 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 S2389564AbfJVWp3 (ORCPT + 99 others); Tue, 22 Oct 2019 18:45:29 -0400 Received: from mail-pf1-f193.google.com ([209.85.210.193]:33827 "EHLO mail-pf1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1731850AbfJVWp3 (ORCPT ); Tue, 22 Oct 2019 18:45:29 -0400 Received: by mail-pf1-f193.google.com with SMTP id b128so11583282pfa.1 for ; Tue, 22 Oct 2019 15:45:28 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=amacapital-net.20150623.gappssmtp.com; s=20150623; h=content-transfer-encoding:from:mime-version:date:message-id:subject :in-reply-to:references:to:cc; bh=7aR+uSzeMahVa2OPNUR1feGVGkqBz5tWi+pFrnNsLQY=; b=HidD9NIIzokyyLiafLDrpYk6/ir9qUK4mM7burZJAZgMgK1Fly7NzNqMBKkKKbhDWN qUVPQpYEuK17Jtw1MFP8s7uh4Z08mCuvkN8ZppirqOQdzGEAm1d0Fi3y1SWXO/HhEgZD 6hlmkjlS6c1tE1+EwnMVW0e+tXRduAvwqHgZmEWj0SIQR+0uRuW14DHeNGs0DGNS6p7B lxnZNpQhD7IFwYwb5gULrGBECcpthxARKeAZQe3WdzPdGnICPZ+iIV6R4aql5KRlTarh KjamU56iYgeAfEsynCOmj5Wceu2AbMFOvy+BONNCxUOGMxPlr6+w3TLiFaPJlRbGvKvr Rbvw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:content-transfer-encoding:from:mime-version:date :message-id:subject:in-reply-to:references:to:cc; bh=7aR+uSzeMahVa2OPNUR1feGVGkqBz5tWi+pFrnNsLQY=; b=ZmIZqaxfv6b/Sza/GJZaCzAZ6phl7/6hlc5B999OeOROKxoE4IuFutAK/WyvPHhQod FdXip9dE1Q1Mjd3Xx39y2Ze/9dFltf/BdT0bU0XcDuqoF7BCL/7TIM/I1A55Pd1z0KM0 1Q7KDv27Dol4VTs7daTxzwHFWUCayhxFUXBi9FpDmbLNcRCeAaGfKFfabnCFFXXl7UTe bhlYICHdbmjv+eWESrEjIjB0TSXooMyCvwq7+wgnai4z51kEX4yEdVujklH+HCiwtNoE C/A78EmFpvBu7NV/l0ybUe1IsNJZweptvYpvrXDQKZ98YKz/tN8CVM2HF4ihp5SsopbT b51Q== X-Gm-Message-State: APjAAAXw4IHR6XlpcYvdd7ia/MRa0YyvFDX1Ftw87J4KQEuieXxBo5Yv uVY2POtilbaXe8es2nNZzSJUWQ== X-Received: by 2002:a17:90a:1a0d:: with SMTP id 13mr7746464pjk.100.1571784328325; Tue, 22 Oct 2019 15:45:28 -0700 (PDT) Received: from [10.145.97.154] ([12.53.65.170]) by smtp.gmail.com with ESMTPSA id q26sm17968253pgk.60.2019.10.22.15.45.27 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Tue, 22 Oct 2019 15:45:27 -0700 (PDT) Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: quoted-printable From: Andy Lutomirski Mime-Version: 1.0 (1.0) Date: Tue, 22 Oct 2019 15:45:26 -0700 Message-Id: <7364B113-DD65-423D-BED3-FF90C4DF8334@amacapital.net> Subject: Re: [PATCH 3/3] x86/ftrace: Use text_poke() In-Reply-To: <20191022215841.2qsmhd6vxi4mwade@ast-mbp.dhcp.thefacebook.com> References: <20191022215841.2qsmhd6vxi4mwade@ast-mbp.dhcp.thefacebook.com> To: Alexei Starovoitov Cc: Steven Rostedt , Peter Zijlstra , Daniel Bristot de Oliveira , LKML , X86 ML , Nadav Amit , Andy Lutomirski , Dave Hansen , Song Liu , Masami Hiramatsu X-Mailer: iPhone Mail (17A878) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org >> On Oct 22, 2019, at 2:58 PM, Alexei Starovoitov wrote: >>=20 >> =EF=BB=BFOn 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). >=20 > your solution is to reduce the overhead. > my solution is to remove it competely. See the difference? >=20 >> 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. >=20 > 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 j= ust: > push rbp=20 > 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=E2=80=99re saving the ar= gs, but rsi is already available in rsi. Just how custom is this bpf program? It seems to clobber no regs (except ar= gs), and it doesn=E2=80=99t return anything. Is it entirely specific to the p= robed function? If so, why not just call it directly? In any event, I think you can=E2=80=99t *just* use text_poke. Something nee= ds to coordinate to ensure that, if you bpf trace an already-kprobed functio= n, the right thing happens. FWIW, if you are going to use a trampoline like this, consider using r11 for= the caller frame instead of rsi. You won=E2=80=99t need to restore it. But= I=E2=80=99m wondering whether the bpf jitted code could just directly acces= s the frame instead of indirecting through a register. (Or am I entirely mis= understanding what rdi is for in your example?)=