Received: by 2002:a25:4158:0:0:0:0:0 with SMTP id o85csp138740yba; Wed, 3 Apr 2019 06:06:29 -0700 (PDT) X-Google-Smtp-Source: APXvYqxr2fm7N/lZWDDjIszuVF3uyUJ7dOOjUBW/3qEjziVYT+dU8PXC42KIvRK4BwfiBqqiE12V X-Received: by 2002:a63:408:: with SMTP id 8mr67503038pge.334.1554296788911; Wed, 03 Apr 2019 06:06:28 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1554296788; cv=none; d=google.com; s=arc-20160816; b=w5mciOSLBG8t4R24UYJ9qTD+9CiYlZNIRUq92bDxAL0e7+bCKErsepfSPYkuzANjR9 YR/f1PHBrtS12ZSp0iILCM7BgYY+GIEAL8X1i8rYvfcQtMkPST2zhCPyzyOMVu1bBbU5 l9r9j5JMc0tfKIJhvr847nCMuLKukBit7D0ZEIfZARK09o9QPiYiYpMgl7yMjLpDVxkV UJqDrJFkOzEq48q/6kZZIDFO18Hb7aSrqMHlVbttDEia7hVmd+ohp7EmQwyPwPvZ1AmH I56aTa0wg/cmAmf2bUyrUxn11fHpfQ9yCtR2BHxDuODGsCgEiybxVcuo4mm3JlE5V1mz W4tA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:user-agent:in-reply-to :content-disposition:mime-version:references:message-id:subject:cc :to:from:date; bh=VG+lM0fp0LQF6U/7EWlBsL8QFeKQ62Y5aay0BiGH31k=; b=n8Ji+FSs0XsEna+awK3xkmqm4aKQeI2cKtVaXGP4w+HHd9WUgETwiYZiw0hsIQa8S1 mUi7cp4gwxBDcxXlwetYpfXBYR6o5rwVy0NoH868n7l3jm2N5bWceAYew1ripqdvwYsR tDrRq02ClZutahDT0lSumFCmAmz9C8o1vSoDX9V+9sKFtk19XJU2W1tMeAhWz60g7pwm yncxaYrBHy+jImO8+qzbsqK9UQAIJHyqC5gJSCHf8hIosEmsRoCuKKWfIH0dnEwgXDpC AHR537AA69lcUnUixXqKm24eHJn3ZraGNdYQJbGJ7APG9jCN6XHDgWloUbHwdNXzfpjK JQoA== 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 n14si13259452pgv.520.2019.04.03.06.06.11; Wed, 03 Apr 2019 06:06:28 -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 S1726206AbfDCNFa (ORCPT + 99 others); Wed, 3 Apr 2019 09:05:30 -0400 Received: from verein.lst.de ([213.95.11.211]:60097 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726064AbfDCNFa (ORCPT ); Wed, 3 Apr 2019 09:05:30 -0400 Received: by newverein.lst.de (Postfix, from userid 2005) id CD3EB68AFE; Wed, 3 Apr 2019 15:05:18 +0200 (CEST) Date: Wed, 3 Apr 2019 15:05:18 +0200 From: Torsten Duwe To: Mark Rutland Cc: Will Deacon , Catalin Marinas , Julien Thierry , Steven Rostedt , Josh Poimboeuf , Ingo Molnar , Ard Biesheuvel , Arnd Bergmann , AKASHI Takahiro , Amit Daniel Kachhap , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, live-patching@vger.kernel.org Subject: Re: [PATCH v7 2/3] arm64: implement ftrace with regs Message-ID: <20190403130518.GA20688@lst.de> References: <20190118163736.6A99268CEB@newverein.lst.de> <20190118163908.E338E68D93@newverein.lst.de> <20190403024842.drobymuwvx6hmwv7@blommer> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190403024842.drobymuwvx6hmwv7@blommer> User-Agent: Mutt/1.5.17 (2007-11-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, Apr 03, 2019 at 03:48:43AM +0100, Mark Rutland wrote: > Hi Torsten, > > Sorry for the long delay prior to this reply. I was hoping you would come up with some code to speed things up :( (For the record, v8 was the latest I sent, but nothing in the locations mentioned here has changed) > On Fri, Jan 18, 2019 at 05:39:08PM +0100, Torsten Duwe wrote: > > --- a/arch/arm64/include/asm/ftrace.h > > +++ b/arch/arm64/include/asm/ftrace.h > > @@ -14,9 +14,24 @@ > > #include > > > > #define HAVE_FUNCTION_GRAPH_FP_TEST > > -#define MCOUNT_ADDR ((unsigned long)_mcount) > > #define MCOUNT_INSN_SIZE AARCH64_INSN_SIZE > > > > +/* > > + * DYNAMIC_FTRACE_WITH_REGS is implemented by adding 2 NOPs at the beginning > > + * of each function, with the second NOP actually calling ftrace. In contrary > > + * to a classic _mcount call, the call instruction to be modified is thus > > + * the second one, and not the only one. > > + */ > > +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS > > +#define ARCH_SUPPORTS_FTRACE_OPS 1 > > +#define REC_IP_BRANCH_OFFSET AARCH64_INSN_SIZE > > +/* All we need is some magic value. Simply use "_mCount:" */ > > +#define MCOUNT_ADDR (0x5f6d436f756e743a) > > I'm really not keen on having a magic constant, and I'd really like to > see MCOUNT_ADDR disappear entirely when the compiler doesn't generate an > mcount call. I'm concerned that this is confusing and fragile. Confusing: agreed. Fragile? don't think so. > I think that it would be better to make the core ftrace API agnostic of > mcount, and to teach it that there's a one-time initialization step for > callsites (which is not necessarily patching a call with a NOP). > > We currently have: > > ftrace_make_nop(mod, rec, addr) > ftrace_make_call(rec, addr) > ftrace_modify_call(rec, old_addr, new_addr) > > ... whereas we could have: > > ftrace_call_init(mod, rec) > ftrace_call_enable(rec, addr) > ftrace_call_disable(rec, addr) > ftrace_call_modify(rec, old_addr, new_addr) > > ... so we wouldn't need to special-case anything for initialization (and > don't need MCOUNT_ADDR at all), and it would be clearer as to what was > happening at each stage. I'm fully on your side here, BUT... This is the dynamic ftrace with regs implementation for aarch64 with the _current_ dynamic ftrace API. Changing the latter is IMO a different issue. This implementation has been tested, up to the point of some preliminary live patching. I propose to commit this and only then change the API for aarch64 and s390 simultaneously, avoiding breakage on ppc64le and x86, of course. (others to be investigated) > > + > > + /* The program counter just after the ftrace call site */ > > + str lr, [sp, #S_PC] > > For consistency with the existing ftrace assembly, please use 'x30' > rather than 'lr'. You could have raised that concern already along with the "fp" issue for v6. I don't have a strong preference here; personally I find fp and lr more readable, but with x29 and x30 one knows where they go. This is only just a waste of time. > > - module_disable_ro(mod); > > - *mod->arch.ftrace_trampoline = trampoline; > > - module_enable_ro(mod, true); > > + /* Check against our well-known list of ftrace entry points */ > > + if (addr == FTRACE_ADDR || addr == FTRACE_REGS_ADDR) { > > These checks exist within install_ftrace_trampoline(), so we don't need > to duplicate them here. True. Code evolution at work. Any other opinions on the dynamic ftrace API change, anyone? Torsten