Received: by 2002:ac0:a582:0:0:0:0:0 with SMTP id m2-v6csp3459429imm; Mon, 8 Oct 2018 04:30:53 -0700 (PDT) X-Google-Smtp-Source: ACcGV61Iby2rcKWFkUE7X/6Wl22QlcG4OTW631VV+mGOp34RXp1UV0ukRLuTTXQCbyJlSPQaTpM5 X-Received: by 2002:a17:902:447:: with SMTP id 65-v6mr23432314ple.325.1538998253403; Mon, 08 Oct 2018 04:30:53 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1538998253; cv=none; d=google.com; s=arc-20160816; b=gpZeCyA7nMpIOoqsyLLDTsxpu3azI+L9FMx+J4pQTNNfK0/hsehg2XkmKWdGHBwNwD tpMEtG31Vgwt9haEqUIXxQtV4YqGTdmUtUU0IGpF4q6gRuUAPFTFmLnFibOwp1+k3/z2 2O/vHsrUMYGM2yYG6SbafmJyRgc5JxYUnuzPzLUSGVAQO3LyRheNhTyuT8QTxJRGO46D pL/4GCrB19O5PvAsceo3cgPiwilR2Oqy+TLQPt/1AA1psusjOmKYFxw18QxzVzpzI6F7 I9/4wVbqD4M6LzRnn4mJhsscqr64fgylGxgHURTXSWRyxn4ev4qHw9ZXuq056mYIE4f9 Ohrw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :references:in-reply-to:mime-version:dkim-signature; bh=12ruE3cLvMG2UNvoPpRcommT1ZKPpRpUd8Rjz0uikDE=; b=USDKjXKBZ/6hLkRTcI5AkLiccGZf7vWJEVnHvpblv9jOEBkO1l2vfFhFyM5DR3whje l2RzsBgYJ8X+jNobTQOTnr2KhF4/nZgQtVL25dY7JtFfhT+fNdmtbMghVE6h4lSDOGlF mN9RJNjs9FPrRbLfgEbAesiV6S9+WOrSP6Y/x4zKzU+EVS0kXOyFji+nmdu7RHkHqXiZ mfKZlvaKz2h5brxh+VMclo0JpRqUyo03alZalijmjOFqufSze72UgJ+A1YKNhvQScK0c ezrUFaWrG+Mms2GGRxUU5otFVt3f8A4gWuwDckPqOmOpanJADXe+3XtAlKQ+5tc64xoV bK7g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=MEI8UIGt; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id 64-v6si18696898pft.177.2018.10.08.04.30.38; Mon, 08 Oct 2018 04:30:53 -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=@linaro.org header.s=google header.b=MEI8UIGt; 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; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linaro.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727388AbeJHSlt (ORCPT + 99 others); Mon, 8 Oct 2018 14:41:49 -0400 Received: from mail-it1-f193.google.com ([209.85.166.193]:51129 "EHLO mail-it1-f193.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726689AbeJHSls (ORCPT ); Mon, 8 Oct 2018 14:41:48 -0400 Received: by mail-it1-f193.google.com with SMTP id j81-v6so10971296ite.0 for ; Mon, 08 Oct 2018 04:30:31 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :cc; bh=12ruE3cLvMG2UNvoPpRcommT1ZKPpRpUd8Rjz0uikDE=; b=MEI8UIGtLE87SFETDYoKCONY+/gzGvT4w9z1GMUxGnom2S5CyWQfEfGOaOdMqYS2JZ Uy4UNrdRF8X4FUKBlLw62tHTJtP1tSSFWEIbIjzK076d3wpPS9jhvzl0J1SoCtmZUHM2 TQAU2igCwIvxkD0rDMdVBtuPMymSiEXl+rzmU= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:in-reply-to:references:from:date :message-id:subject:to:cc; bh=12ruE3cLvMG2UNvoPpRcommT1ZKPpRpUd8Rjz0uikDE=; b=eHUKBxT4RAt8RYxJLrHpjevN/5UscdgRf6V/lRwdxX9YRUdbH2XIoMK8r5VtMCInnJ vvFRKgq5798R3mCck3LUtyS6vT2Bl1gGfTGnk55r5+38ZboddzwQbyrOAp+Ak+2Z7rOa 74cmpDXQ1F/jnpDIFSP+8RbUyH5G8SL4xMKNz0vNo/tv8bPqaQGE3NSIv4hBTvM3WBGt ysPTm4z1bTbGKRDsfOWAEj40uZUdUuMYURpy1QVb/CzJWTL7XfYIu7SWgF+phq/mObaI W674WSjXJDRF12pefsdN9JKFTJXciNOKuX+fYywH9JRiJSQqnt08B/Pa9UrN5MjK4vR5 v0Mw== X-Gm-Message-State: ABuFfohkpcVl468N9DVWzDL9EZvOCV8WupXJ81BzRxmk7aACPamc9+vx AW+MpJLGB05IVZPpKUCvDMh+Iy/jc26Im0xqe3VFwA== X-Received: by 2002:a24:a10b:: with SMTP id y11-v6mr12347572ite.148.1538998230836; Mon, 08 Oct 2018 04:30:30 -0700 (PDT) MIME-Version: 1.0 Received: by 2002:a6b:5910:0:0:0:0:0 with HTTP; Mon, 8 Oct 2018 04:30:30 -0700 (PDT) In-Reply-To: <20181006093905.46276505@vmware.local.home> References: <20181006015110.653946300@goodmis.org> <20181006015720.634688468@goodmis.org> <20181006121211.GA5663@hirez.programming.kicks-ass.net> <20181006093905.46276505@vmware.local.home> From: Ard Biesheuvel Date: Mon, 8 Oct 2018 13:30:30 +0200 Message-ID: Subject: Re: [POC][RFC][PATCH 1/2] jump_function: Addition of new feature "jump_function" To: Steven Rostedt Cc: Peter Zijlstra , Linux Kernel Mailing List , Linus Torvalds , Ingo Molnar , Andrew Morton , Thomas Gleixner , Masami Hiramatsu , Mathieu Desnoyers , Matthew Helsley , "Rafael J . Wysocki" , David Woodhouse , Paolo Bonzini , Josh Poimboeuf , Jason Baron , Jiri Kosina , Andy Lutomirski Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On 6 October 2018 at 15:39, Steven Rostedt wrote: > On Sat, 6 Oct 2018 14:12:11 +0200 > Peter Zijlstra wrote: > >> On Fri, Oct 05, 2018 at 09:51:11PM -0400, Steven Rostedt wrote: >> > +#define arch_dynfunc_trampoline(name, def) \ >> > + asm volatile ( \ >> > + ".globl dynfunc_" #name "; \n\t" \ >> > + "dynfunc_" #name ": \n\t" \ >> > + "jmp " #def " \n\t" \ >> > + ".balign 8 \n \t" \ >> > + : : : "memory" ) >> >> Bah, what is it with you people and trampolines. Why can't we, just like >> jump_label, patch the call directly? >> >> The whole call+jmp thing is silly, don't do that. It just wrecks I$ and >> is slower for no real reason afaict. > > My first attempt was to do just that. But to add a label at the > call site required handling all the parameters too. See my branch: > ftrace/jump_function-v1 for how ugly it got (and it didn't work). > >> >> Steve, also see: >> >> https://lkml.kernel.org/r/20181005081333.15018-1-ard.biesheuvel@linaro.org > > Interesting. I don't have time to look at it at the moment to see what > was done, but will do so in the near future. > > Remember, this was a proof of concept and even with the trampolines, it > showed a great level of improvement. One thought was to do a > "recordmcount.c" type of action to find where the calls were and patch > them directly at boot up. I tried to keep the API the same where this > could actually be done as an improvement later. > > Perhaps a gcc plugin might work too. > > I'll have to see what Ard did to handle the function parameters. > I didn't. My approach is just a generic function pointer which can be overridden by the arch to be emitted as a trampoline instead. Patching the call directly simply isn't feasible without compiler support like we have with asm goto for jump_labels. The use case I am proposing is providing different implementations of crypto routines or CRC computation etc without having to rely on function pointers, but still keep them as loadable modules. These routines are a) heavy weight or we wouldn't bother providing alternatives in the first place, and b) likely to have a considerable I$ footprint already (and crypto libraries that have encrypt/decrypt/setkey or init/update/final entry points will end up with multiple trampolines in a single I-cache line). Also, the actual patching only occurs on module load/unload. I have no idea whether this reasoning applies to Steven's use case as well, though, I haven't looked at his patches (I wasn't on cc)