From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 10011C433F5 for ; Tue, 26 Oct 2021 12:07:05 +0000 (UTC) Received: from bombadil.infradead.org (bombadil.infradead.org [198.137.202.133]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by mail.kernel.org (Postfix) with ESMTPS id C8F0B60295 for ; Tue, 26 Oct 2021 12:07:04 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.4.1 mail.kernel.org C8F0B60295 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=arm.com Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=bombadil.20210309; h=Sender: Content-Transfer-Encoding:Content-Type:List-Subscribe:List-Help:List-Post: List-Archive:List-Unsubscribe:List-Id:In-Reply-To:MIME-Version:References: Message-ID:Subject:Cc:To:From:Date:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=TfmBBIiDREjAho9DjtQd8xmwSDdtoLj8zWK8nQEtnyc=; b=xkqmP4dhPFogsW 8TStyRsTAlD4labc6CidC8Hvx1Z1dBWSRVAE4pOqjAEulRRhbo+sr2ckiCaUwAQIJnYPGiW7CJJQx ppr73E0ZLQ8ekt3anplHDOZfJlJG9OvjBFfoRnK/do8UkAag5vt8HJTEv3eyR4WNlsZnxsTuGDdwQ tZ+AT9ewy1QcNl71mB6dKd8EefTNBgAntGRe7Rvb86Zn/PtIJw+lAePZRfM4WqOs2A16YF7QQ9OaH SCVrz83N2Ld8x1v+TyfLAkxJK3NYdcbrt3zBzUBRiIPktolaevvwaHPOqIi6adzfh1VH9WF/FgKFB FGaDyxT9L8nhE9pUQV3w==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfLCz-001jfV-Iv; Tue, 26 Oct 2021 12:05:37 +0000 Received: from foss.arm.com ([217.140.110.172]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mfLCv-001jdm-2r for linux-arm-kernel@lists.infradead.org; Tue, 26 Oct 2021 12:05:34 +0000 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 54E8C1FB; Tue, 26 Oct 2021 05:05:31 -0700 (PDT) Received: from C02TD0UTHF1T.local (unknown [10.57.74.144]) by usa-sjc-imap-foss1.foss.arm.com (Postfix) with ESMTPSA id A3E453F73D; Tue, 26 Oct 2021 05:05:28 -0700 (PDT) Date: Tue, 26 Oct 2021 13:05:16 +0100 From: Mark Rutland To: madvenka@linux.microsoft.com Cc: broonie@kernel.org, jpoimboe@redhat.com, ardb@kernel.org, nobuta.keiya@fujitsu.com, sjitindarsingh@gmail.com, catalin.marinas@arm.com, will@kernel.org, jmorris@namei.org, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org Subject: Re: [PATCH v10 05/11] arm64: Make dump_stacktrace() use arch_stack_walk() Message-ID: <20211026120516.GA34073@C02TD0UTHF1T.local> References: <20211015025847.17694-1-madvenka@linux.microsoft.com> <20211015025847.17694-6-madvenka@linux.microsoft.com> <20211025164925.GB2001@C02TD0UTHF1T.local> MIME-Version: 1.0 Content-Disposition: inline In-Reply-To: <20211025164925.GB2001@C02TD0UTHF1T.local> X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211026_050533_239725_5C5417AD X-CRM114-Status: GOOD ( 26.45 ) X-BeenThere: linux-arm-kernel@lists.infradead.org X-Mailman-Version: 2.1.34 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org On Mon, Oct 25, 2021 at 05:49:25PM +0100, Mark Rutland wrote: > From f3e66ca75aff3474355839f72d123276028204e1 Mon Sep 17 00:00:00 2001 > From: Mark Rutland > Date: Mon, 25 Oct 2021 13:23:11 +0100 > Subject: [PATCH] arm64: ftrace: use HAVE_FUNCTION_GRAPH_RET_ADDR_PTR > > When CONFIG_FUNCTION_GRAPH_TRACER is selected, and the function graph: > tracer is in use, unwind_frame() may erroneously asscociate a traced > function with an incorrect return address. This can happen when starting > an unwind from a pt_regs, or when unwinding across an exception > boundary. > > The underlying problem is that ftrace_graph_get_ret_stack() takes an > index offset from the most recent entry added to the fgraph return > stack. We start an unwind at offset 0, and increment the offset each > time we encounter `return_to_handler`, which indicates a rewritten > return address. This is broken in two cases: > > * Between creating a pt_regs and starting the unwind, function calls may > place entries on the stack, leaving an abitrary offset which we can > only determine by performing a full unwind from the caller of the > unwind code. While this initial unwind is open-coded in > dump_backtrace(), this is not performed for other unwinders such as > perf_callchain_kernel(). > > * When unwinding across an exception boundary (whether continuing an > unwind or starting a new unwind from regs), we always consume the LR > of the interrupted context, though this may not have been live at the > time of the exception. Where the LR was not live but happened to > contain `return_to_handler`, we'll recover an address from the graph > return stack and increment the current offset, leaving subsequent > entries off-by-one. > > Where the LR was not live and did not contain `return_to_handler`, we > will still report an erroneous address, but subsequent entries will be > unaffected. It turns out I had this backwards, and we currently always *skip* the LR when unwinding across regs, because: * The entry assembly creates a synthetic frame record with the original FP and the ELR_EL1 value (i.e. the PC at the point of the exception), skipping the LR. * In arch_stack_walk() we start the walk from regs->pc, and continue with the frame record, skipping the LR. * In the existing dump_backtrace, we skip until we hit a frame record whose FP value matches the FP in the regs (i.e. the synthetic frame record created by the entry assembly). That'll dump the ELR_EL1 value, then continue to the next frame record, skipping the LR. So case two is bogus, and only case one can happen today. This cleanup shouldn't trigger the WARN_ON_ONCE() in unwind_frame(), and we can fix the missing LR entry in a subsequent cleanup. Thanks, Mark. _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel