Received: by 2002:a05:6a10:9848:0:0:0:0 with SMTP id x8csp3524458pxf; Mon, 15 Mar 2021 11:28:42 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyh7JMlK24BAEFyQ3tK/4lSdLWrRLKCUYC8MMt+vEbN+f0CQrZmTG5tLOv8pnxyovzhb98F X-Received: by 2002:a17:906:1113:: with SMTP id h19mr24829941eja.478.1615832922712; Mon, 15 Mar 2021 11:28:42 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1615832922; cv=none; d=google.com; s=arc-20160816; b=Z6QXFxC+SxjxizPE4O1DtzFtHCBDPzkefoUpGnm6Di3NmXgfVnj2hcfv/5cQVRQqwq qFNJXC0gsd1T+JkAqnWmY6ZHaJmJj3O3RIMIRQlb2u6CGrMuORSG8+ZPB9WvwqfdUgTh UuFRtDL3MkOwOju+uTHkQ8mGvWgb5puG53BfwmENXcWeiTsW5XsRszdM1jEB8fBMxNfT 23Hdg0qsrZiMDLPu8ZAQ39F8bnzJw2Le+Y6rdAOfF+vf1w40EgWQXquyhTEjLtqH1hF1 OoleUGLj2HpM4QyTrR6xnDleiC84MAITztWsoxxt6I+ir5L99lpjBtgniySg5g++nNsy JIEg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :user-agent:references:in-reply-to:message-id:date:subject:cc:to :from:dkim-signature; bh=9rr4zAcJ7NQOWSrubmEUVU6NqB2EiyYIxLZakDxDFZs=; b=l1pOgLu3S5ThMGwoE1Ze6MjRNcKrxxKXpaBnIxV/M332JclvsMPxO2TBaH6hjxsR9Z jOJrg2TOl6jgBjHTazp7mi8bIuYZ2onrq4qg8ZOtNlCqpLU2nEj1DyP4I9xrxnRy7nVt a+ldf6TJ/lBu8cURVZsy8Zaz3PVAI9xsYN6Gzt8MWvzzXu+Qs8ILMDzsh8sEKkvXCSyx mQdSNLeZGrX53ENKMBOJKsXfozUCjPMD+f9s2uHOmsFzbwXkuUM35Lc+iPw+8JB2l+VK 53AUG/UlLdArBmdO3P6GfDFkaqcu9V6ZRlIceU6DYZbYSteoUVmqgrJ1iPO060euxs+1 JTRA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Fi7rn+Ul; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g3si11521561edp.527.2021.03.15.11.28.12; Mon, 15 Mar 2021 11:28:42 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@linuxfoundation.org header.s=korg header.b=Fi7rn+Ul; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linuxfoundation.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239333AbhCOOcP (ORCPT + 99 others); Mon, 15 Mar 2021 10:32:15 -0400 Received: from mail.kernel.org ([198.145.29.99]:36788 "EHLO mail.kernel.org" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S233218AbhCOOBM (ORCPT ); Mon, 15 Mar 2021 10:01:12 -0400 Received: by mail.kernel.org (Postfix) with ESMTPSA id 4F32364EF2; Mon, 15 Mar 2021 14:00:40 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=linuxfoundation.org; s=korg; t=1615816841; bh=UXjvJ/kmV1CUUTL04/+RiehY5nWhHbbe602RiwrZrcc=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=Fi7rn+UlkTpB8uWrMikYcnW4kPWUt7DIHpJSGC5cfu3O3pXAioz8dbPn7uTxV4nEp tcWwwmyvi9Fo8ilB4atlHWO0jIdzbceBYGmKRqjx7lZWNct2QX6hdzQm32+XyERc6S LEnXTJ66OrJueq9ldWDANLfnyQqOkKC0/aBKQhWo= From: gregkh@linuxfoundation.org To: linux-kernel@vger.kernel.org Cc: Greg Kroah-Hartman , stable@vger.kernel.org, Michael Ellerman , Sasha Levin Subject: [PATCH 5.10 145/290] powerpc/64: Fix stack trace not displaying final frame Date: Mon, 15 Mar 2021 14:53:58 +0100 Message-Id: <20210315135546.810203864@linuxfoundation.org> X-Mailer: git-send-email 2.30.2 In-Reply-To: <20210315135541.921894249@linuxfoundation.org> References: <20210315135541.921894249@linuxfoundation.org> User-Agent: quilt/0.66 MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Greg Kroah-Hartman From: Michael Ellerman [ Upstream commit e3de1e291fa58a1ab0f471a4b458eff2514e4b5f ] In commit bf13718bc57a ("powerpc: show registers when unwinding interrupt frames") we changed our stack dumping logic to show the full registers whenever we find an interrupt frame on the stack. However we didn't notice that on 64-bit this doesn't show the final frame, ie. the interrupt that brought us in from userspace, whereas on 32-bit it does. That is due to confusion about the size of that last frame. The code in show_stack() calls validate_sp(), passing it STACK_INT_FRAME_SIZE to check the sp is at least that far below the top of the stack. However on 64-bit that size is too large for the final frame, because it includes the red zone, but we don't allocate a red zone for the first frame. So add a new define that encodes the correct size for 32-bit and 64-bit, and use it in show_stack(). This results in the full trace being shown on 64-bit, eg: sysrq: Trigger a crash Kernel panic - not syncing: sysrq triggered crash CPU: 0 PID: 83 Comm: sh Not tainted 5.11.0-rc2-gcc-8.2.0-00188-g571abcb96b10-dirty #649 Call Trace: [c00000000a1c3ac0] [c000000000897b70] dump_stack+0xc4/0x114 (unreliable) [c00000000a1c3b00] [c00000000014334c] panic+0x178/0x41c [c00000000a1c3ba0] [c00000000094e600] sysrq_handle_crash+0x40/0x50 [c00000000a1c3c00] [c00000000094ef98] __handle_sysrq+0xd8/0x210 [c00000000a1c3ca0] [c00000000094f820] write_sysrq_trigger+0x100/0x188 [c00000000a1c3ce0] [c0000000005559dc] proc_reg_write+0x10c/0x1b0 [c00000000a1c3d10] [c000000000479950] vfs_write+0xf0/0x360 [c00000000a1c3d60] [c000000000479d9c] ksys_write+0x7c/0x140 [c00000000a1c3db0] [c00000000002bf5c] system_call_exception+0x19c/0x2c0 [c00000000a1c3e10] [c00000000000d35c] system_call_common+0xec/0x278 --- interrupt: c00 at 0x7fff9fbab428 NIP: 00007fff9fbab428 LR: 000000001000b724 CTR: 0000000000000000 REGS: c00000000a1c3e80 TRAP: 0c00 Not tainted (5.11.0-rc2-gcc-8.2.0-00188-g571abcb96b10-dirty) MSR: 900000000280f033 CR: 22002884 XER: 00000000 IRQMASK: 0 GPR00: 0000000000000004 00007fffc3cb8960 00007fff9fc59900 0000000000000001 GPR04: 000000002a4b32d0 0000000000000002 0000000000000063 0000000000000063 GPR08: 000000002a4b32d0 0000000000000000 0000000000000000 0000000000000000 GPR12: 0000000000000000 00007fff9fcca9a0 0000000000000000 0000000000000000 GPR16: 0000000000000000 0000000000000000 0000000000000000 00000000100b8fd0 GPR20: 000000002a4b3485 00000000100b8f90 0000000000000000 0000000000000000 GPR24: 000000002a4b0440 00000000100e77b8 0000000000000020 000000002a4b32d0 GPR28: 0000000000000001 0000000000000002 000000002a4b32d0 0000000000000001 NIP [00007fff9fbab428] 0x7fff9fbab428 LR [000000001000b724] 0x1000b724 --- interrupt: c00 Signed-off-by: Michael Ellerman Link: https://lore.kernel.org/r/20210209141627.2898485-1-mpe@ellerman.id.au Signed-off-by: Sasha Levin --- arch/powerpc/include/asm/ptrace.h | 3 +++ arch/powerpc/kernel/asm-offsets.c | 2 +- arch/powerpc/kernel/process.c | 2 +- 3 files changed, 5 insertions(+), 2 deletions(-) diff --git a/arch/powerpc/include/asm/ptrace.h b/arch/powerpc/include/asm/ptrace.h index e2c778c176a3..7bb064ad04d8 100644 --- a/arch/powerpc/include/asm/ptrace.h +++ b/arch/powerpc/include/asm/ptrace.h @@ -62,6 +62,9 @@ struct pt_regs }; #endif + +#define STACK_FRAME_WITH_PT_REGS (STACK_FRAME_OVERHEAD + sizeof(struct pt_regs)) + #ifdef __powerpc64__ /* diff --git a/arch/powerpc/kernel/asm-offsets.c b/arch/powerpc/kernel/asm-offsets.c index c2722ff36e98..5c125255571c 100644 --- a/arch/powerpc/kernel/asm-offsets.c +++ b/arch/powerpc/kernel/asm-offsets.c @@ -307,7 +307,7 @@ int main(void) /* Interrupt register frame */ DEFINE(INT_FRAME_SIZE, STACK_INT_FRAME_SIZE); - DEFINE(SWITCH_FRAME_SIZE, STACK_FRAME_OVERHEAD + sizeof(struct pt_regs)); + DEFINE(SWITCH_FRAME_SIZE, STACK_FRAME_WITH_PT_REGS); STACK_PT_REGS_OFFSET(GPR0, gpr[0]); STACK_PT_REGS_OFFSET(GPR1, gpr[1]); STACK_PT_REGS_OFFSET(GPR2, gpr[2]); diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c index d421a2c7f822..1a1d2657fe8d 100644 --- a/arch/powerpc/kernel/process.c +++ b/arch/powerpc/kernel/process.c @@ -2170,7 +2170,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack, * See if this is an exception frame. * We look for the "regshere" marker in the current frame. */ - if (validate_sp(sp, tsk, STACK_INT_FRAME_SIZE) + if (validate_sp(sp, tsk, STACK_FRAME_WITH_PT_REGS) && stack[STACK_FRAME_MARKER] == STACK_FRAME_REGS_MARKER) { struct pt_regs *regs = (struct pt_regs *) (sp + STACK_FRAME_OVERHEAD); -- 2.30.1