Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp7423850imu; Tue, 22 Jan 2019 05:57:11 -0800 (PST) X-Google-Smtp-Source: ALg8bN5Zb+dub8aU5BvOnMezM82CbxQlQDH4utlBMwGQPNq+z46HYJFZmsETMiQvMdsZ86IsSAsk X-Received: by 2002:a62:32c4:: with SMTP id y187mr34693672pfy.195.1548165431541; Tue, 22 Jan 2019 05:57:11 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1548165431; cv=none; d=google.com; s=arc-20160816; b=bRRhoXaGXQK9FQnqxbmLrp4cB3P0Zv4Z7YqhVoK721lYq/4onvUgrzdexp1BEAqUQG Lk2mN1T7uTX42QkSXi0oH9RfZpKsHID/ugrs2kWJgkyxHgFd/PWG9TGe64Imw1YjsvpB Tk2T5zDS8X8EKePBFOoI5UCvCdro+fnkMVGG0QhhowGGIHY5Nvc2jqdhqaDaIinHkS/M oJYK+UngcuOglf+HXfpnKT+oq0su9inrbsApHSjNC/4OWW8CDkrGkhZCW84e2WKSw3QI urm9Ap19xNppFd3Cel1Cy3d47mQniYV3UevXoWCSndb2GYR5h+gemCj6SNbBVwjlt+W3 aeDQ== 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 :in-reply-to:references:mime-version:dkim-signature; bh=va/webB65xAQkHXqaHqTjHSAjNDLESnhLUArsDNowQQ=; b=lXRisIdgKfSPy1K/bzGAkQpI57f1XWQrSaWnx/sEn4NhCd5tdYkvvtPDvY2mfo/6M8 i2c7eLaOqTjYiVg15s8zD5ro4+X09N7+BYl/xu3Pl5y8FEoqQvloTDin5Biq3KQRSy82 52VHAbaBLEv/tk05vAOND4WiNxe8lFAemHstQ7CsjJPqJl4AelZdu8UsNGjLuW5GsAUj xVPfsbl8qvk4GRQwOwqdYVBWOnJ0Sn9RsScdsqL5stI3T9jfkfQa8qM4n/GRMDi6vroZ 3WBCcAL6EwL5u77fENCY+vwZkwsn3WktfVeMwA+h6e1T5WynbS6/k51vxweAq2+A8k3T OIOg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linaro.org header.s=google header.b=iByubt0Y; 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 a4si15097040pls.262.2019.01.22.05.56.55; Tue, 22 Jan 2019 05:57:11 -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; dkim=pass header.i=@linaro.org header.s=google header.b=iByubt0Y; 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 S1728698AbfAVNzZ (ORCPT + 99 others); Tue, 22 Jan 2019 08:55:25 -0500 Received: from mail-io1-f65.google.com ([209.85.166.65]:44250 "EHLO mail-io1-f65.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728539AbfAVNzZ (ORCPT ); Tue, 22 Jan 2019 08:55:25 -0500 Received: by mail-io1-f65.google.com with SMTP id r200so19103368iod.11 for ; Tue, 22 Jan 2019 05:55:24 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=va/webB65xAQkHXqaHqTjHSAjNDLESnhLUArsDNowQQ=; b=iByubt0YbEMmC4ppjgC9ANZeBGsR4BavV8L/2iNC6MyZe+L66+TPQalc2P2SPSGash XJj5pf/CJ+xLVEdDlARRU9RTmZX+w8xKPJGEQwMVZ+Tr1DJhmUhaD43xOvi9+AaWTdS2 iXxGmkF68bx3/5py9Z+hCoiCJ6Zlv24sChnZ0= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=va/webB65xAQkHXqaHqTjHSAjNDLESnhLUArsDNowQQ=; b=PVDi5BVDcD0g1sU8OiprL7L+B2LO+6nN8oI2hdso3W93CIqzZywAu5AeEN+4YBUPrg ZZbp2kH1kth36syrmU617BmZ7ozv206nAw1NjfRTxogvcF87CrvYz5m5IfJ3Lx3/F98Y m4bmCkJ8Epnxe2x/KSygjSQLDzibnaPZhMwEQr8FDV9pZnj7rqP13KdEqjSWbBViu+sd Mg1DSDg+tlWgbl1WVVoCMQFD0PlSDE1gAnXquSNKQDsrBGsUZrIwmGtNhKvt+BxaYsvK e9KrpUj4uslB5WLEdtNWZWFmb7loEkLX2dYsaEAbrrzEWGRWyKI0qXU/bdcaprmnRSWF cWRw== X-Gm-Message-State: AJcUukdu5DXj1Tsxc5SeST8QB2oQVJIMlkRUTkRW/aKdFpKpbG9KlPuI sMy1LqgoaG/TVd5SJzD5ST1S32HIQJzsqoFE4BtwhQ== X-Received: by 2002:a5e:c206:: with SMTP id v6mr19964688iop.60.1548165323852; Tue, 22 Jan 2019 05:55:23 -0800 (PST) MIME-Version: 1.0 References: <20190118163736.6A99268CEB@newverein.lst.de> <20190118163908.E338E68D93@newverein.lst.de> <20190122132832.GB16778@lst.de> In-Reply-To: <20190122132832.GB16778@lst.de> From: Ard Biesheuvel Date: Tue, 22 Jan 2019 14:55:12 +0100 Message-ID: Subject: Re: [PATCH v7 2/3] arm64: implement ftrace with regs To: Torsten Duwe Cc: Julien Thierry , Mark Rutland , Will Deacon , Catalin Marinas , Steven Rostedt , Josh Poimboeuf , Ingo Molnar , Arnd Bergmann , AKASHI Takahiro , Amit Daniel Kachhap , "Singh, Balbir" , linux-arm-kernel , Linux Kernel Mailing List , live-patching@vger.kernel.org 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 Tue, 22 Jan 2019 at 14:28, Torsten Duwe wrote: > > On Tue, Jan 22, 2019 at 10:18:17AM +0000, Julien Thierry wrote: > > Hi Torsten, > > > > A few suggestions below. > > > > > +#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:" */ > > > > Nit: Should the casing be "_mcount" ? > > No! The string makes it clear what it's supposed to be and the peculiar > casing makes it unique and leaves no doubt were it came from. So whenever > you see this register value in a crash dump you don't have to wonder about > weird linkage errors, as it surely did not originate from a symtab. > In that case, do you need to deal with endianness here? > > > +#define MCOUNT_ADDR (0x5f6d436f756e743a) > > > +#else > > > +#define REC_IP_BRANCH_OFFSET 0 > > > +#define MCOUNT_ADDR ((unsigned long)_mcount) > > > +#endif > > > + > > > #ifndef __ASSEMBLY__ > > > #include > > > > > > --- a/arch/arm64/kernel/entry-ftrace.S > > > +++ b/arch/arm64/kernel/entry-ftrace.S > > > @@ -10,6 +10,7 @@ > > > */ > > > > > > #include > > > +#include > > > #include > > > #include > > > #include > ^^^^^^^^^^^^^^^^^^^^^^^^^^^ > > > + > > > +ENTRY(ftrace_common) > > > + > > > + mov x3, sp /* pt_regs are @sp */ > > > + ldr_l x2, function_trace_op, x0 > > > + mov x1, x9 /* parent IP */ > > > + sub x0, lr, #8 /* function entry == IP */ > > > > The #8 is because we go back two instructions right? Can we use > > #(AARCH64_INSN_SIZE * 2) instead? > > Hmm, was already included, so why not. (same below) > > > > +#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); > > > > The last argument of aarch64_insn_gen_branch_imm() is an enum, not a > > boolean. > > > > You should use AARCH64_INSN_BRANCH_LINK here which happens to be equal to 1. > > That's what you get when you keep copying code... > Good catch, thanks! > > > > + * initially; the NOPs are already there. So instead, > > > + * put the LR saver there ahead of time, in order to avoid > > > + * any race condition over patching 2 instructions. > > > + */ > > > + if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS) && > > > + addr == MCOUNT_ADDR) { > > > > This works, however it feels a bit weird since core code asked to > > generate a NOP but not only we don't generate it but we put another > > instruction instead. > > It's not the first time weird x86 sets the standards and all others > need workarounds. But here it just came handy to abuse this call :-) > > > I think it would be useful to state that the replacement of mcount calls > > by nops is only ever done once at system initialization. > > > > Or maybe have a intermediate function: > > > > static int ftrace_setup_patchable_entry(unsigned long addr) > > { > > u32 old, new; > > > > old = aarch64_insn_gen_nop(); > > new = MOV_X9_X30; > > pc -= REC_IP_BRANCH_OFFSET; > > return ftrace_modify_code(pc, old, new, validate); > > } > > > > [...] > > > > if (IS_ENABLED(CONFIG_DYNAMIC_FTRACE_WITH_REGS) && > > addr == MCOUNT_ADDR) > > return ftrace_setup_patchable_entry(pc); > > > > > > This way it clearly show that this is a setup/init corner case. > > I'll definitely consider this. > > Thanks for the input, > > Torsten > >