Received: by 2002:a25:7ec1:0:0:0:0:0 with SMTP id z184csp8428154ybc; Fri, 29 Nov 2019 10:20:04 -0800 (PST) X-Google-Smtp-Source: APXvYqy4sBGMYHdINqZb4QxupiBHtYyXKKSRhSnewlcpqmhR6kcZYCz+hz0QOElgvpnbXEWbZ+iy X-Received: by 2002:a17:906:4d46:: with SMTP id b6mr989187ejv.79.1575051603877; Fri, 29 Nov 2019 10:20:03 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1575051603; cv=none; d=google.com; s=arc-20160816; b=C9J1gPwu+AtU/8XAs1QpEuPV3ZUpmTLt9QB0dqRNyP4mMEpVNDTZuFG63SipYrO/K9 mRCwwhEe8azZip3mgJaIywgN43I5A2+bKC7mWRmBe9NJ9nlaJ+f1+2plIaVvjMW8pYTw hfSogIhWpPfBbtFyrIZy8exvMSwVHtD/eY32cGZFHJClvE2TVLVkaOgJQctDclL4aONd PW80eRXwmVefkR0WEWfbBdkD6ggi2Zus9GZFFwZSbg3JpKeRVJmRIiMYgb45uefnhRjL jQ/dWYmfDo2kjWosKSP21nJHP74m3BiVxLQieXvzSdbTAaxBI2EsmxTyTwsaGmGEvoSd Damw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:mime-version:user-agent:references :message-id:in-reply-to:subject:cc:to:from:date; bh=Z1AwXpyKP3GQuAZkPMkZRoN7wncqCMlyqFZ5+d2FbYg=; b=x2LmbuUJJZ40t4/REF2nLbkVj+gdp70zXLacjUvxDeoX/PeCGUTNzW0Tn39P5YH0/x ZJd857U6C6Ie0uicjhkyG70dZpsE2dfXoDc94sqdRTXZehVJZU7COdExciDNjs2Dwup2 E1Rd9Yva1cCQzZ6+3LUZZaN2m5E1VccY/dNZILsNPPhoQHr4PbFD74czo/F5GIgDTukp t1pe5H0nd4jBS93JNlPCI0IlMon8UKmDyygezPWh/mXGHyGbFjDE7gdwxaOPWyOuqKuL HtpLnBMuFHR1FJYksu1E4Ymk5CE84CzbhTp5ZojHHCMC4LSUYzWdzOdJ+FhQAkSCaIAH R2Hw== 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 c22si15111242eja.111.2019.11.29.10.19.39; Fri, 29 Nov 2019 10:20:03 -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 S1727172AbfK2SQy (ORCPT + 99 others); Fri, 29 Nov 2019 13:16:54 -0500 Received: from mx2.suse.de ([195.135.220.15]:44892 "EHLO mx1.suse.de" rhost-flags-OK-OK-OK-FAIL) by vger.kernel.org with ESMTP id S1727107AbfK2SQx (ORCPT ); Fri, 29 Nov 2019 13:16:53 -0500 X-Virus-Scanned: by amavisd-new at test-mx.suse.de Received: from relay2.suse.de (unknown [195.135.220.254]) by mx1.suse.de (Postfix) with ESMTP id 79ED4B469; Fri, 29 Nov 2019 18:16:51 +0000 (UTC) Date: Fri, 29 Nov 2019 19:16:50 +0100 (CET) From: Miroslav Benes To: Vasily Gorbik cc: heiko.carstens@de.ibm.com, borntraeger@de.ibm.com, jpoimboe@redhat.com, joe.lawrence@redhat.com, linux-s390@vger.kernel.org, linux-kernel@vger.kernel.org, jikos@kernel.org, pmladek@suse.com, nstange@suse.de, live-patching@vger.kernel.org Subject: Re: [PATCH v4 2/2] s390/livepatch: Implement reliable stack tracing for the consistency model In-Reply-To: Message-ID: References: <20191106095601.29986-5-mbenes@suse.cz> User-Agent: Alpine 2.21 (LSU 202 2017-01-01) MIME-Version: 1.0 Content-Type: text/plain; charset=US-ASCII Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, 29 Nov 2019, Vasily Gorbik wrote: > From: Miroslav Benes > > The livepatch consistency model requires reliable stack tracing > architecture support in order to work properly. In order to achieve > this, two main issues have to be solved. First, reliable and consistent > call chain backtracing has to be ensured. Second, the unwinder needs to > be able to detect stack corruptions and return errors. > > The "zSeries ELF Application Binary Interface Supplement" says: > > "The stack pointer points to the first word of the lowest allocated > stack frame. If the "back chain" is implemented this word will point to > the previously allocated stack frame (towards higher addresses), except > for the first stack frame, which shall have a back chain of zero (NULL). > The stack shall grow downwards, in other words towards lower addresses." > > "back chain" is optional. GCC option -mbackchain enables it. Quoting > Martin Schwidefsky [1]: > > "The compiler is called with the -mbackchain option, all normal C > function will store the backchain in the function prologue. All > functions written in assembler code should do the same, if you find one > that does not we should fix that. The end result is that a task that > *voluntarily* called schedule() should have a proper backchain at all > times. > > Dependent on the use case this may or may not be enough. Asynchronous > interrupts may stop the CPU at the beginning of a function, if kernel > preemption is enabled we can end up with a broken backchain. The > production kernels for IBM Z are all compiled *without* kernel > preemption. So yes, we might get away without the objtool support. > > On a side-note, we do have a line item to implement the ORC unwinder for > the kernel, that includes the objtool support. Once we have that we can > drop the -mbackchain option for the kernel build. That gives us a nice > little performance benefit. I hope that the change from backchain to the > ORC unwinder will not be too hard to implement in the livepatch tools." > > Since -mbackchain is enabled by default when the kernel is compiled, the > call chain backtracing should be currently ensured and objtool should > not be necessary for livepatch purposes. > > Regarding the second issue, stack corruptions and non-reliable states > have to be recognized by the unwinder. Mainly it means to detect > preemption or page faults, the end of the task stack must be reached, > return addresses must be valid text addresses and hacks like function > graph tracing and kretprobes must be properly detected. > > Unwinding a running task's stack is not a problem, because there is a > livepatch requirement that every checked task is blocked, except for the > current task. Due to that, we can consider a task's kernel/thread stack > only and skip the other stacks. > > [1] 20180912121106.31ffa97c@mschwideX1 [not archived on lore.kernel.org] > > Signed-off-by: Vasily Gorbik Signed-off-by: Miroslav Benes M