Received: by 2002:ad5:474a:0:0:0:0:0 with SMTP id i10csp1609034imu; Sat, 5 Jan 2019 03:08:49 -0800 (PST) X-Google-Smtp-Source: ALg8bN5Q9g/sg5qa08J81z7Sv4B3FP/rLq4bPoLYh4KTqmii6diK20BYVUGbLS66B5Hkt2RZubQT X-Received: by 2002:a17:902:380c:: with SMTP id l12mr52897108plc.326.1546686529405; Sat, 05 Jan 2019 03:08:49 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1546686529; cv=none; d=google.com; s=arc-20160816; b=ZdBgm1Zf2OPJvnYh4Nx2+AxV40E+vC3ikgifmhI/b58USFQmwqxsAJNEy8vDuAyCmB o2rTdNs/lxzTGdBv29KNEUR8kPFu3w3EoddVpZGDZXKmFvzHVuPPbR9ykmKSrdi8ObEM PTY7zJL408NY8IjQQyQt0+40oz4YnqbyTA5/JW4rq3Vr9FjGiSMURI+B1EjZj1wf39FE MqwG+GH3BWkNTKW0+AwiXDShdKmvfj0wcocSx+mPbwNAcuAErsi9OEiNAUNMIqgyqwWn bLm67ta7GNF+lmaRnQCHJLxI72ym7DCzs6R+41ki71zGDfX1h7yb6oOu8aWtv7FVraEU mhsw== 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=+fy0daVlpF5GTIhPXDX8AgNQPQVItIhoo5sIBb2qubw=; b=VLzxjBHxfeIKadai9eCSvur+EaUEsMEBGVOvfIFohNhaDDCZiIfMsaI0p3e1WUgkr7 F08nWn0fCNcBXukuH9OCkKmXhywGj9da/OaqgyXSCucg2cTF/N2CIaz3Eo74k0CFbtTp urvJE+4yVo9Sxc9tf3LKiTWZH1KMUUvtIYLNuvnDh3ST8dWWwdHhGb365ubZ5gms8V/t UYNLOFOGnRK+6KRo1pDCJOPDTXFVpa9knNC5MzkIdvcopD+wodxuXX9f7+7h6d1RtUpN AP6SvBagsxItHy2Tm+xkjIABMRakI5esBazZETZoeKaYPyp7/iyFaxNsus6Rzr1MkEOi FM2Q== 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 f35si58225096pgf.449.2019.01.05.03.08.31; Sat, 05 Jan 2019 03:08:49 -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 S1726242AbfAELF6 (ORCPT + 99 others); Sat, 5 Jan 2019 06:05:58 -0500 Received: from verein.lst.de ([213.95.11.211]:44352 "EHLO newverein.lst.de" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726108AbfAELF6 (ORCPT ); Sat, 5 Jan 2019 06:05:58 -0500 Received: by newverein.lst.de (Postfix, from userid 107) id 3D8F268DD6; Sat, 5 Jan 2019 12:05:56 +0100 (CET) X-Spam-Checker-Version: SpamAssassin 3.3.1 (2010-03-16) on newverein.lst.de X-Spam-Level: X-Spam-Status: No, score=-0.2 required=5.0 tests=ALL_TRUSTED,BAYES_50 autolearn=disabled version=3.3.1 Received: from lst.de (p5B33FA9D.dip0.t-ipconnect.de [91.51.250.157]) by newverein.lst.de (Postfix) with ESMTPSA id 2DDF367329; Sat, 5 Jan 2019 12:05:50 +0100 (CET) Date: Sat, 5 Jan 2019 12:05:43 +0100 From: Torsten Duwe To: Steven Rostedt Cc: Mark Rutland , Will Deacon , Catalin Marinas , Julien Thierry , 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 v6] arm64: implement ftrace with regs Message-ID: <20190105110543.GA4298@lst.de> References: <20190104141053.360F768D93@newverein.lst.de> <20190104175017.GA7157@lakrids.cambridge.arm.com> <20190104130648.02657f3f@gandalf.local.home> <20190104224145.GA28236@lst.de> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20190104224145.GA28236@lst.de> User-Agent: Mutt/1.10.1 (2018-07-13) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Jan 04, 2019 at 11:41:45PM +0100, Torsten Duwe wrote: > On Fri, Jan 04, 2019 at 01:06:48PM -0500, Steven Rostedt wrote: > > On Fri, 4 Jan 2019 17:50:18 +0000 > > Mark Rutland wrote: > > > > > At Linux Plumbers, I had a conversation with Steve Rostedt, and we came > > > to the conclusion that (withut heavyweight synchronization) patching two > > > NOPs at runtime isn't safe, since a CPU might have executed the first > > > NOP as a NOP before another CPU patches both instructions. So a CPU > > > might execute: > > > > > > NOP > > > BL ftrace_regs_caller > > > > > > ... rather than the expected: > > > > > > MOV X9, X30 > > > BL ftrace_regs_caller > > > > > > ... and therefore X9 contains some UNKNOWN value, rather than the > > > original LR value. > > I'm perfectly aware of that; an earlier version had barriers, attempting > to avoid just that, which Mark(?) wrote weren't neccessary. > > But is this a realistic scenario? All function entries are aligned 8 bytes. > Are there arm64 implementations out there that fetch only 4 bytes and > give a chance to mess with the 2nd 4 bytes? You at arm.com should know, and > I won't be surprised if the answer is a weird "yes". Or maybe it's just > another erratum lurking somewhere... > > My point is: those 2 insn will _never_ be split by any alignment > boundary > 8; does that mean anything, have you considered this? Forget that. Steve mentioned the keyword *interrupt*, which creates a completely different situation. In short, only the instruction pointer will be saved; and i-cache and pipeline will be freshly reloaded on return, so this threat is highly unlikely (interrupt taken exactly after 1st nop), but not impossible. "Puking horses..." as we say in German. > > > I wonder if we could solve that by patching the kernel at build-time, to > > > add the MOV X9, X30 in place of the first NOP. If we were to do that, we > > > could also update the addresses to pooint at the second NOP, simplifying > > > the changes to the runtime code. > > > > You can also patch it at boot up when there's only one CPU running, and > > interrupts are disabled. > > May I remind about possible performance hits? Even the NOPs had a tiny impact > on certain in-order implementations. I'd rather switch between the mov and > a "b +2". This one however still holds. Torsten