Received: by 2002:ac0:946b:0:0:0:0:0 with SMTP id j40csp312769imj; Thu, 7 Feb 2019 04:52:23 -0800 (PST) X-Google-Smtp-Source: AHgI3IYRSKb86qIVcPnpVowjSsPb3fa31GB6KAqD3GHnHtKtqi7OGLiiS9nsRtbfIfYm6tld9KxU X-Received: by 2002:a63:e615:: with SMTP id g21mr14907348pgh.290.1549543943081; Thu, 07 Feb 2019 04:52:23 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1549543943; cv=none; d=google.com; s=arc-20160816; b=sJaCYiInHyA4zN4JP8rqZaIImxDrV3Gbz12EkwIUj7Nm82xe2Pwu0uhbyj9dyn3Scz tpAgoXHS/7HNHEsu0UL82jriQ9HgArvZdB9moqSsv/1wDG0sUoipqfUT8+ai3jgF66w2 l2BPtJyRetAgXOT9fqGMa5mN5nHBCR5RXk1IvY40gc6uFIxjIK02U4pU+J8Xp62N7fNw q9d2vLpGo1HOdMGZTkX4Lpi8cakuxQ2GSqIbqJCU/KlkmReZTJ6dU99dKggcLoTmcn77 foHbXrC0MfknwxzKZwAXqBVRWVmunwUH0wMkmddsZ95MIt66nna5xm9XwxUdmev/VqBh /ldA== 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=PXGy0DeOz6tuYTD8oaFQE0Or87DniPa6ZIixhu1yzdI=; b=uT8LIF3g4d36gUYcyibXXfLGlN8d16H3AgzWnNcNnk/V6sFGvn4OGBj8gfS/Q3sFO7 oTQFoSYWRUcncK48ZoeXuK8KN544ssmyuFII+0Az9UaFkakgv1evQM17ljao1/Qe6eCD DZoMXoR5NfslxXD1AuQzYMfrosj+THBj2tW3MO7kYxr9XlXNA81mt9ZM9jUX3Lwa4BQ0 t+akK+6W4aEH2FIrW2G0Mg/YXvQS16Shur9j3upO8l0b/epOTsz+5P3AQX3+w8pOrPpO N8YvUDyfsUuJ+ew8UuLXsxJqQXItuH9Wu8bYBfWvoxUnWl84lDZIaWsZeLMZ88HLNYEi qMog== 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 n125si7308020pga.179.2019.02.07.04.52.06; Thu, 07 Feb 2019 04:52:23 -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 S1727057AbfBGMwC (ORCPT + 99 others); Thu, 7 Feb 2019 07:52:02 -0500 Received: from verein.lst.de ([213.95.11.211]:36638 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726769AbfBGMwB (ORCPT ); Thu, 7 Feb 2019 07:52:01 -0500 Received: by newverein.lst.de (Postfix, from userid 2005) id E431B6FA81; Thu, 7 Feb 2019 13:51:59 +0100 (CET) Date: Thu, 7 Feb 2019 13:51:59 +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: <20190207125159.GA19818@lst.de> References: <20190118163736.6A99268CEB@newverein.lst.de> <20190118163908.E338E68D93@newverein.lst.de> <20190206150524.GA28892@lst.de> <198550d8-78d4-6e30-0179-b5e07dd140f8@arm.com> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <198550d8-78d4-6e30-0179-b5e07dd140f8@arm.com> 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, Feb 07, 2019 at 10:33:50AM +0000, Julien Thierry wrote: > > > On 06/02/2019 15:05, Torsten Duwe wrote: > > 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? > > > > I don't see really much documentation on that function. As far as I can > tell it is only called once for each site (and if it didn't, we'd always > be placing the same instruction, but I agree it wouldn't be nice). It > could depend on how far you can expand the notion of "adjusting" :) . I've been thinking this over and I'm considering to make an ftrace_modify_code with verify and warn_once if it fails. Then read the insn back and bug_on should it not be the lr saver. Any objections? > Steven, do you have an opinion on whether it would be acceptable to > modify function entry code in ftrace_call_adjust() ? Yes, Steve's vote first. Torsten