Received: by 2002:a25:d7c1:0:0:0:0:0 with SMTP id o184csp4148245ybg; Mon, 21 Oct 2019 04:38:55 -0700 (PDT) X-Google-Smtp-Source: APXvYqweoR8KhQIQOUQuVCJKi/UNiQwPMk9QVT0UHVS1c6bthrGHricCS3uTU+PI1BfTOwqro5mh X-Received: by 2002:a05:6402:213:: with SMTP id t19mr12735484edv.7.1571657935604; Mon, 21 Oct 2019 04:38:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1571657935; cv=none; d=google.com; s=arc-20160816; b=k6z12BeRGgYQFHbsTR0Bkvp3Gm1+ApISpeCxewZ/waXX/pjsouCE6z0WZhIl9yGlYu zNspO54VDdvuAeuhnUNDRK0UyEzPXHNL7gv9CNwdLzrbiI7d1xeOjc8dDH32MmaiQv2g 4jRusI10o0ilLSrW6nGwSk34wkzTzIQEfo+1rCfjk/3rb8D1X+0pl0Ee6v702JcFG2BC xpvT6pcFVtD5O/vGoikfAKP7kqtovk8wc2XywK2ou0H1pPBV3PQR3+coJD6nq62FDMdW czqYNmIh8Wz8HSymyNU71PTpoihjpij7uPmR1rJX8wdfkjL3fXEuUX7xbV3ViUw3Z1/p 5h7g== 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=1igUsA1Cc8KgQGPooah+EqK2nVMSoGpshx366q9IWYI=; b=XdN6D7b5ytFzAo7YeJa4bcOZTLkUPDIkBl4MlhoR+wWKHL/oEu4iAT9b7PVYvkLip3 SVeNOGI9rhqowLsczj+7I9ZfTHlZCiKvRMNmiXOcRYwASzxa1Jojpoq8ZZp0QDy6HbcI UQlEU979sUo/SJTIJZX5BAnR9uuk0brRDtRD3iEVybNI/l1cOvxZBKjlfz9pTVXyci6h 8b56Bx8uerli1AZYYtM/q3CF+l+jXLk6iBfxX6EGdjcdd7X5u6I/wS7dUSkRlo8CsasN yiZ2dzdnzQ/NMZ7qKIgb8Y+fOdxh2Tti30nnIPY1U9D14llZWasNjl/Pb5kMj4GaLTDW Lp0g== 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 n8si8554012ejh.169.2019.10.21.04.38.31; Mon, 21 Oct 2019 04:38:55 -0700 (PDT) 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 S1728461AbfJULiE (ORCPT + 99 others); Mon, 21 Oct 2019 07:38:04 -0400 Received: from [217.140.110.172] ([217.140.110.172]:50154 "EHLO foss.arm.com" rhost-flags-FAIL-FAIL-OK-OK) by vger.kernel.org with ESMTP id S1727725AbfJULiE (ORCPT ); Mon, 21 Oct 2019 07:38:04 -0400 Received: from usa-sjc-imap-foss1.foss.arm.com (unknown [10.121.207.14]) by usa-sjc-mx-foss1.foss.arm.com (Postfix) with ESMTP id 1AE0CEBD; Mon, 21 Oct 2019 04:37:32 -0700 (PDT) Received: from lakrids.cambridge.arm.com (usa-sjc-imap-foss1.foss.arm.com [10.121.207.14]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id 16AFE3F718; Mon, 21 Oct 2019 04:37:29 -0700 (PDT) Date: Mon, 21 Oct 2019 12:37:25 +0100 From: Mark Rutland To: Torsten Duwe Cc: Jiri Kosina , Arnd Bergmann , Julien Thierry , Catalin Marinas , Ard Biesheuvel , Will Deacon , linux-kernel@vger.kernel.org, Steven Rostedt , AKASHI Takahiro , Ingo Molnar , Ruslan Bilovol , Josh Poimboeuf , Amit Daniel Kachhap , live-patching@vger.kernel.org, linux-arm-kernel Subject: Re: [PATCH v8 0/5] arm64: ftrace with regs Message-ID: <20191021113724.GA56589@lakrids.cambridge.arm.com> References: <0f8d2e77-7e51-fba8-b179-102318d9ff84@arm.com> <20190311114945.GA5625@lst.de> <20190408153628.GL6139@lakrids.cambridge.arm.com> <20190409175238.GE9255@fuggles.cambridge.arm.com> <20190724161500.GG2624@lakrids.cambridge.arm.com> <20191016175841.GF46264@lakrids.cambridge.arm.com> <20191018174100.GC18838@lakrids.cambridge.arm.com> <20191019130135.10de9324@blackhole.lan> MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Disposition: inline In-Reply-To: <20191019130135.10de9324@blackhole.lan> User-Agent: Mutt/1.11.1+11 (2f07cb52) (2018-12-01) Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Sat, Oct 19, 2019 at 01:01:35PM +0200, Torsten Duwe wrote: > Hi Mark! Hi Torsten! > On Fri, 18 Oct 2019 18:41:02 +0100 Mark Rutland > wrote: > > > In the process of reworking this I spotted some issues that will get > > in the way of livepatching. Notably: > > > > * When modules can be loaded far away from the kernel, we'll > > potentially need a PLT for each function within a module, if each can > > be patched to a unique function. Currently we have a fixed number, > > which is only sufficient for the two ftrace entry trampolines. > > > > IIUC, the new code being patched in is itself a module, in which > > case we'd need a PLT for each function in the main kernel image. > > When no live patching is involved, obviously all cases need to have > been handled so far. And when a live patching module comes in, there > are calls in and out of the new patch code: > > Calls going into the live patch are not aware of this. They are caught > by an active ftrace intercept, and the actual call into the LP module > is done in klp_arch_set_pc, by manipulating the intercept (call site) > return address (in case thread lives in the "new world", for > completeness' sake). This is an unsigned long write in C. I was under the impression that (at some point) the patch site would be patched to call the LP code directly. From the above I understand that's not the case, and it will always be directed via the regular ftrace entry code -- have I got that right? Assuming that is the case, that sounds fine to me, and sorry for the noise. > All calls going _out_ from the KLP module are newly generated, as part > of the KLP module building process, and are thus aware of them being > "extern" -- a PLT entry should be generated and accounted for in the > KLP module. Yup; understood. > > We have a few options here, e.g. changing which memory size model we > > use, or reserving space for a PLT before each function using > > -f patchable-function-entry=N,M. > > Nonetheless I'm happy I once added the ,M option here. You never know :) Yup; we may have other reasons to need this in future (and I see parisc uses this today). > > * There are windows where backtracing will miss the callsite's caller, > > as its address is not live in the LR or existing chain of frame > > records. Thus we cannot claim to have a reliable stacktrace. > > > > I suspect we'll have to teach the stacktrace code to handle this as > > a special-case. > > Yes, that's where I had to step back. The unwinder needs to stop where > the chain is even questionable. In _all_ cases. Missing only one race > condition means a lurking inconsistency. Sure. I'm calling this out now so that we don't miss this in future. I've added comments to the ftrace entry asm to this effect for now. > OTOH it's not a problem to report "not reliable" when in doubt; the > thread in question will then get woken up and unwind itself. > It is only an optimisation to let all kernel threads which are > guaranteed to not contain any patched functions sleep on. I just want to make it clear that some care will be needed if/when adding CONFIG_HAVE_RELIABLE_STACKTRACE so that we handle this case correctly. > > I'll try to write these up, as similar probably applies to other > > architectures with a link register. > > I thought I'd quickly give you my feedback upfront here. Thanks; it's much appreciated! Mark.