Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp3977738imu; Mon, 12 Nov 2018 03:53:09 -0800 (PST) X-Google-Smtp-Source: AJdET5fmLp+qZz73QL4oDlthy0zWQqBlU1jEYwF3OJcygtw1voYOUywbJnFkI20XWMdUZ0JakGl1 X-Received: by 2002:a17:902:b598:: with SMTP id a24-v6mr629283pls.231.1542023589259; Mon, 12 Nov 2018 03:53:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1542023589; cv=none; d=google.com; s=arc-20160816; b=uab7EPXaI4otkf+FAbbmDOWmZxtquNXxX1gwwRQy6jgfBT0Fi5UPgKY7FY1evaj+cz AzG0HrPxG3CwZ1RvuKEbaCXx524wGCu5Br2K3s+2BoM8Yvw0BktNF50ZQEc85T/BShfJ qwInMJAOqU5KxHFrj4pFcpWRbQ+0V9y1Lqep8gmGdGlKvlmk705qv4qT1tRCERn7SAgz cy0by0mY7tcLs+pCbpSgQ9iUPW+qgQrBfR4D4r/CuXy8ei02vGwa+DXvrTC5y/p15r3r yANmDbzn2Edrs7OPDKzpdvGgRAoyzJMS1+2yO1zASM0fMg7qNyvhBAmVAl98nISDxS6C aYyg== 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=pG5CULZSLOgdvVCuE/qhb0peKqRYX6mTxK94jfWo4dU=; b=qaxAXqV4SSGbVe9EObrSaSfGHcPV0ddD2gOzF0NOfLhej1eQWsHH/QG1FYayewz7yT zkgART9oGQ6GRS22lkZyl2BT15lIGT0qih5V9+odjMOKOp2RU3a+OqF8DAekxQsKb9cl ch3HDLCVP6dG1XjTTmknRVqRZZxmN3VcmLz0RF6iRMJrTk2D4w295M5rsTk9AODsbHeq uDBlriVJBU8nx4MUBXoDqKugQasYl43Q+drVe4FtRSV6lJGChODNOciqP9k5zxLLZOIt +Etim3rqz2cnRlivcZQqMYAGMnk5LrSqHnuDSTCKpTDq4DjaIhHWF6hlJhw4FYnRu02x BA8Q== 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 o4-v6si15052147pgj.306.2018.11.12.03.52.53; Mon, 12 Nov 2018 03:53:09 -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 S1729341AbeKLVoJ (ORCPT + 99 others); Mon, 12 Nov 2018 16:44:09 -0500 Received: from verein.lst.de ([213.95.11.211]:50058 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728302AbeKLVoJ (ORCPT ); Mon, 12 Nov 2018 16:44:09 -0500 Received: by newverein.lst.de (Postfix, from userid 2005) id 152A967358; Mon, 12 Nov 2018 12:51:13 +0100 (CET) Date: Mon, 12 Nov 2018 12:51:13 +0100 From: Torsten Duwe To: Ard Biesheuvel Cc: Will Deacon , Catalin Marinas , Julien Thierry , Steven Rostedt , Josh Poimboeuf , Ingo Molnar , Arnd Bergmann , AKASHI Takahiro , linux-arm-kernel , Linux Kernel Mailing List , live-patching@vger.kernel.org Subject: Re: [PATCH v4 1/3] arm64: implement ftrace with regs Message-ID: <20181112115112.GB30967@lst.de> References: <20181026142008.D922868C94@newverein.lst.de> <20181026142148.6353A68C94@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 Thu, Nov 08, 2018 at 01:12:42PM +0100, Ard Biesheuvel wrote: > > On 26 October 2018 at 16:21, Torsten Duwe wrote: > > @@ -162,6 +165,114 @@ ftrace_graph_call: // ftrace_graph_cal > > > > mcount_exit > > ENDPROC(ftrace_caller) > > +#else /* CONFIG_DYNAMIC_FTRACE_WITH_REGS */ > > + > > +/* > > + * Since no -pg or similar compiler flag is used, there should really be > > + * no reference to _mcount; so do not define one. Only some value for > > + * MCOUNT_ADDR is needed for comparison. Let it point here to have some > > + * sort of magic value that can be recognised when debugging. > > + */ > > + .global _mcount > > +_mcount: > > + ret /* make it differ from regs caller */ > > + > > +ENTRY(ftrace_regs_caller) > > + /* callee's preliminary stack frame: */ > > + stp fp, x9, [sp, #-16]! > > Does the 'fp' alias for x29 work with older assemblers? I guess it > does not matter gor GCC 8+ code, but be careful when you rewrite > existing stuff. I had gotten the impression the fp alias was there ever since, so I used it for readability. Thanks for the notification, I'll double check. > > + mov fp, sp > > + > > + /* our stack frame: */ > > + stp fp, lr, [sp, #-S_FRAME_SIZE]! > > If sizeof(struct pt_regs) == S_FRAME_SIZE), you should subtract 16 > additional bytes here This is intentional :-] At the end of pt_regs there's a "stackframe", which now aligns with the "preliminary" frame I create for the callee. Please tell me what the struct member is good for if not for an actual callee stack frame... I thought it was a neat idea. > > + > > +ftrace_common: > > + /* > > + * At this point we have 2 new stack frames, and x9 pointing > > + * at a pt_regs which we can populate as needed. > > + */ > > + > > + /* save function arguments */ > > + stp x0, x1, [x9] > > + stp x2, x3, [x9, #S_X2] > > + stp x4, x5, [x9, #S_X4] > > + stp x6, x7, [x9, #S_X6] > > + stp x8, x9, [x9, #S_X8] > > + > > x9 is not a function argument, and if it were, you'd have clobbered it > by now. Please use a single 'str' and store x8 only This way the x9 slot in pt_regs will be undefined. Is that ok with everybody? > > +ftrace_common_return: > > + add x9, sp, #16 /* advance to pt_regs for restore */ > > + > > + ldp x0, x1, [x9] > > + ldp x2, x3, [x9, #S_X2] > > + ldp x4, x5, [x9, #S_X4] > > + ldp x6, x7, [x9, #S_X6] > > + ldp x8, x9, [x9, #S_X8] > > + > > Same as above. It also deserves a mention that you are relying on the > absence of IPA-RA, and so x9..x18 are guaranteed to be dead at > function entry, and so they don't need to be restored here. Sure, I can quote some ABI spec here :-/ I just wish all arm code was such well documented. > > --- a/arch/arm64/kernel/ftrace.c > > +++ b/arch/arm64/kernel/ftrace.c > > @@ -65,18 +65,61 @@ int ftrace_update_ftrace_func(ftrace_fun > > return ftrace_modify_code(pc, 0, new, false); > > } > > > > +#ifdef CONFIG_ARM64_MODULE_PLTS > > +static int install_ftrace_trampoline(struct module *mod, unsigned long *addr) > > +{ > > + struct plt_entry trampoline, *mod_trampoline; > > + trampoline = get_plt_entry(*addr); > > + > > + if (*addr == FTRACE_ADDR) > > + mod_trampoline = mod->arch.ftrace_trampoline; > > + else if (*addr == FTRACE_REGS_ADDR) > > + mod_trampoline = mod->arch.ftrace_regs_trampoline; > > Could we do something like > > if (*addr == FTRACE_ADDR) > mod_trampoline = &mod->arch.ftrace_trampoline[0]; > else if (*addr == FTRACE_REGS_ADDR) > mod_trampoline = &mod->arch.ftrace_trampoline[1]; > > and get rid of the additional struct field and pointer? "0" and "1" won't make it obvious which one has the regs tracing, but besides that, I like the idea of making this a small array. Other opinions? Torsten