Received: by 2002:ac0:8c8e:0:0:0:0:0 with SMTP id r14csp732202ima; Wed, 6 Feb 2019 07:29:45 -0800 (PST) X-Google-Smtp-Source: AHgI3IbVWmlXPdNceBYON7W73fQRB8CaLfHXrVgWOxadab7cPUi3d8x50nG3+QC9fV1cFV0Mcrqi X-Received: by 2002:a17:902:a984:: with SMTP id bh4mr3770747plb.266.1549466985708; Wed, 06 Feb 2019 07:29:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549466985; cv=none; d=google.com; s=arc-20160816; b=AhJxpSkZ2n2vXOIGlyckLXPyiJo9ZEAbMJFGQjIh7KEu0DRImbhawP9eBHdXTQiG0y o1kffhEOeQITqfxgRggzlbxTPeFC3WDd/SPxFjUZ95bjwPQyAKG23ehg+VD3GpmYeKg/ k72fCLcK43U9qxOwSwsn4wH76vJ9htP1fgnnrHMRwN02IBXLUGvlfA8GZdvVVcu5zzEy lK8iXjyjS6BI6iFib3s9QH2iZYf+EE/KlDcfbMZ8FUtIziSRqQMjXhQchUWuAmb8NYhC ojZSv5ZDsGwt8jlwVgBLHHnnsXRtVvFgB8nCow/Oql7aE7UcGFvTGgKX/KqR7E0/Ovmx mBUg== 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=0EZB2KKkRsBcZyrsMe6jz+SapUdDkutrqAC7OscZiNc=; b=JQEz7TbYSYWt+/9jcG0UbOdCeQBIfI+p7GvNfGDYu8FE+fDeHcUjm9hXKYb6YUvtLy 3n65rKJweKODJQ6YDADh2znsnW1ziF5/YMCRMJmYOLpTYuptZoHCa9X9Bve51Ma90F0H RVhuKUQYsVB1V/qFLuA96WjO6ziksV/51Yi/3ZyHvwmbi9U3vYMqtYwkSwMZ/qeAHqLF Xj3oWAqVqhU0jyeudLpIqvVQ9p8JqwUSCV2neOnH4vyEantuKpcX/8F7Cg8+v6zMPvHz Bs/xY1iEYWCCtcJ1T5T453aqeBcRH2Z+98R4APgYQMmUrud4WPl4O0Q57lKvSTUuVRAh 6wmw== 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 e192si6371508pfc.28.2019.02.06.07.29.29; Wed, 06 Feb 2019 07:29:45 -0800 (PST) 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 S1730463AbfBFPF0 (ORCPT + 99 others); Wed, 6 Feb 2019 10:05:26 -0500 Received: from verein.lst.de ([213.95.11.211]:60151 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726767AbfBFPF0 (ORCPT ); Wed, 6 Feb 2019 10:05:26 -0500 Received: by newverein.lst.de (Postfix, from userid 2005) id B3CA168D93; Wed, 6 Feb 2019 16:05:24 +0100 (CET) Date: Wed, 6 Feb 2019 16:05:24 +0100 From: Torsten Duwe To: Julien Thierry Cc: Mark Rutland , Will Deacon , Catalin Marinas , 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: <20190206150524.GA28892@lst.de> References: <20190118163736.6A99268CEB@newverein.lst.de> <20190118163908.E338E68D93@newverein.lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: 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, Feb 06, 2019 at 08:59:44AM +0000, Julien Thierry wrote: > Hi Torsten, > > On 18/01/2019 16:39, Torsten Duwe wrote: > > > --- a/arch/arm64/kernel/ftrace.c > > +++ b/arch/arm64/kernel/ftrace.c > > @@ -133,17 +163,45 @@ int ftrace_make_call(struct dyn_ftrace * > > return ftrace_modify_code(pc, old, new, true); > > } > > > > +#ifdef CONFIG_DYNAMIC_FTRACE_WITH_REGS > > +int ftrace_modify_call(struct dyn_ftrace *rec, unsigned long old_addr, > > + unsigned long addr) > > +{ > > + unsigned long pc = rec->ip + REC_IP_BRANCH_OFFSET; > > + u32 old, new; > > + > > + old = aarch64_insn_gen_branch_imm(pc, old_addr, true); > > + new = aarch64_insn_gen_branch_imm(pc, addr, true); > > + > > + return ftrace_modify_code(pc, old, new, true); > > +} > > +#endif > > + > > /* > > * Turn off the call to ftrace_caller() in instrumented function > > */ > > int ftrace_make_nop(struct module *mod, struct dyn_ftrace *rec, > > unsigned long addr) > > { > > - unsigned long pc = rec->ip; > > + unsigned long pc = rec->ip + REC_IP_BRANCH_OFFSET; > > Sorry to come back on this patch again, but I was looking at the ftrace > code a bit, and I see that when processing the ftrace call locations, > ftrace calls ftrace_call_adjust() on every ip registered as mcount > caller (or in our case patchable entries). This ftrace_call_adjust() is > arch specific, so I was thinking we could place the offset in here once > and for all so we don't have to worry about it in the future. Now that you mention it - yes indeed that's the correct facility to fix the deviating address, as Steve has also confirmed. I had totally forgotten about this hook. > Also, I'm unsure whether it would be safe, but we could patch the "mov > x9, lr" there as well. In theory, this would be called at init time > (before secondary CPUs are brought up) and when loading a module (so I'd > expect no-one is executing that code *yet*. > > If this is possible, I think it would make things a bit cleaner. This is in fact very tempting, but it will introduce a nasty side effect to ftrace_call_adjust. Is there any obvious documentation that specifies guarantees about ftrace_call_adjust being called exactly once for each site? Torsten