Received: by 2002:ac0:8c8e:0:0:0:0:0 with SMTP id r14csp643963ima; Wed, 6 Feb 2019 06:10:05 -0800 (PST) X-Google-Smtp-Source: AHgI3Ib8T+ukLhGxvFtlvJcgq8ac3JoVGcZ54INzxyT5P3rDF/JQqJi352CZSXaOCQhHRr/SeBWB X-Received: by 2002:a17:902:fa2:: with SMTP id 31mr10972791plz.75.1549462205699; Wed, 06 Feb 2019 06:10:05 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549462205; cv=none; d=google.com; s=arc-20160816; b=KdDx3tHHoM8jF1m4z/0gQCeBFnPhXkzBY42uN0IdvmNEEVPwuMkyPItaug19Geyt5Z NSrj+bRrJCK382B4L8Fbi0kJykcisdxnJZH/+zUiMRyka+j/Xh6r5gi7X5+3jFuq7JN/ iRL5caD6C8JbCdYIIZWOXt9k9IO0YycxoWZvrM639w7maNkeYP4aphvXm6ApyiXa1qZp 0EB255ecZmfHm7bKPGbF3u6phR4rJ+fGO6/d2ZFqMRiBm+45jNrph4vs+6n9/squ29FG A23LjMJENDJesh0XqqI2+17ZDOG7fDqqU/qR/a5FbMLhTr5Q9uoEIjMBYwfpqvijL0zj MjGg== 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=SbmEkjNTwZIFVi7R9dz1D1mWyXDFxvJ3bqE+pSlNvtA=; b=ab483dZZZNyZf30lcW3gKFMCPC94duFiJvuBOAjWrTbNQ7eZjXMhQRWGqjG01sNsIQ 7yy46y4DAxKfJ7bJkn9XK8VnAfC2RjHVEixFSCYZMY61W1pV7KBIeuLXyHO8SVG6TTnR EWaE44+pEfpeHN2+DVvze2OtX9p6HHulzgF4szll+OHq/thMdGrAx0YvCUF6R3h541jy XHWlhCxKUr2LmU7cXFqgQ6K6oSw+IjSbsu9Zv8l29M1rXmL+ye44Hi3eUb/zZLGE/rOF aDRfjXzDibaK1AqhAvCu1kZa80akxDhM6WVdO9rHwbuin4aS02M60qbXE7LBcWfXUIO3 ZikA== 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 x8si6099491plv.129.2019.02.06.06.09.48; Wed, 06 Feb 2019 06:10:05 -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 S1730275AbfBFOJM (ORCPT + 99 others); Wed, 6 Feb 2019 09:09:12 -0500 Received: from mail.kernel.org ([198.145.29.99]:56888 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727929AbfBFOJL (ORCPT ); Wed, 6 Feb 2019 09:09:11 -0500 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 28B7D20844; Wed, 6 Feb 2019 14:09:09 +0000 (UTC) Date: Wed, 6 Feb 2019 09:09:07 -0500 From: Steven Rostedt To: Julien Thierry Cc: Torsten Duwe , Mark Rutland , Will Deacon , Catalin Marinas , 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: <20190206090907.311259df@gandalf.local.home> In-Reply-To: References: <20190118163736.6A99268CEB@newverein.lst.de> <20190118163908.E338E68D93@newverein.lst.de> X-Mailer: Claws Mail 3.16.0 (GTK+ 2.24.32; x86_64-pc-linux-gnu) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Content-Transfer-Encoding: 7bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Wed, 6 Feb 2019 08:59:44 +0000 Julien Thierry wrote: > Hi Torsten, > > On 18/01/2019 16:39, Torsten Duwe wrote: > > Once gcc8 adds 2 NOPs at the beginning of each function, replace the > > first NOP thus generated with a quick LR saver (move it to scratch reg > > x9), so the 2nd replacement insn, the call to ftrace, does not clobber > > the value. Ftrace will then generate the standard stack frames. > > > > Note that patchable-function-entry in GCC disables IPA-RA, which means > > ABI register calling conventions are obeyed *and* scratch registers > > such as x9 are available. > > > > Introduce and handle an ftrace_regs_trampoline for module PLTs, right > > after ftrace_trampoline, and double the size of this special section. > > > > Signed-off-by: Torsten Duwe > > > > --- > > > > Mark, if you see your ftrace entry macro code being represented correctly > > here, please add your sign-off, As I've initially copied it from your mail. > > > > --- > > arch/arm64/include/asm/ftrace.h | 17 ++++- > > arch/arm64/include/asm/module.h | 3 > > arch/arm64/kernel/entry-ftrace.S | 125 +++++++++++++++++++++++++++++++++++++-- > > arch/arm64/kernel/ftrace.c | 114 ++++++++++++++++++++++++++--------- > > arch/arm64/kernel/module-plts.c | 3 > > arch/arm64/kernel/module.c | 2 > > 6 files changed, 227 insertions(+), 37 deletions(-) > > [...] > > > --- 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. The ftrace_call_adjust() is there in case what is saved in the mcount table is different than what is needed for the addresses. Which this looks to be the case here. -- Steve