Received: by 2002:a05:6a10:f347:0:0:0:0 with SMTP id d7csp1162509pxu; Fri, 27 Nov 2020 00:54:21 -0800 (PST) X-Google-Smtp-Source: ABdhPJwhM2Ohp9Y4VkHM/Ez+jkt306cl+1RQsNrrVyzUta/IfU7VJvm2/zId3xtKJRkpfVeKXi/A X-Received: by 2002:a50:d681:: with SMTP id r1mr6498197edi.290.1606467261387; Fri, 27 Nov 2020 00:54:21 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1606467261; cv=none; d=google.com; s=arc-20160816; b=bP6bv39IK1w+h/FkBU9oWk43nwe0Hv0bJA6OFcfzacrILgcu85LUyBXshvsi92xP5x Zz47VwU8sSpVmx1Wjt71p+54XufJi19DKlVXpAEgilJvq3xCv01CarjshHFua99pUcqb 649r4jGXisiJRngPCZd8R2JIkKaU0FXyzyyPFiM06ilR8jQ/0CsUzcmMFBrd3tASA2iu t3N19i+cSbcCZqbjNCXm9RV+7OuzBpjgVcF3iuN3ETK6iE87Nu4+BdNTiVKJAnTTHt5U WLVQDpExe25MyjRvEufMexBN1dyb3c+US8a6WrEiJzEiYjbC0jCrsf0eQ8YgYNDy1KHb Cbfg== 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 :message-id:date:subject:cc:to:from; bh=xzSPnIWiPfAZ9ySgsyFJ5jYF+cT/49wMtqQ2GP1pym0=; b=ldbA+PImS93XRcDPFv3GpXKaa9fsPj89az8vy1uYnQ/1OeGyp+u1C+OYhRmR/1kDik 7Hgxn1flhBINHxgpQXji1OX+UNMsKEnK3Y3XJJkCiX2anJ21RO/O09oYHwQYtA22gAwt XjGo1lrAUqYYVEmJ4RNQnV/gyi+xyiu0Vk//tPDgRqdc/3CqoEQsu+iKDRiujt7L+abf iwL7jiCRBxcp5Pro1L0sRixQOkdluEMR7rSiZV5eF/OPvF/pDT8BoJIcGc5ucik2X4oS X3KIk1xAo09ElxVDrV3T2twAeTGxJr1BmcXpO7RDUEtZaazB2wq3oml0k1SIYB0zI2bu jKsg== ARC-Authentication-Results: i=1; mx.google.com; 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 Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id dp16si5112962ejc.625.2020.11.27.00.53.58; Fri, 27 Nov 2020 00:54:21 -0800 (PST) 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; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1729299AbgK0IlO (ORCPT + 99 others); Fri, 27 Nov 2020 03:41:14 -0500 Received: from szxga07-in.huawei.com ([45.249.212.35]:8418 "EHLO szxga07-in.huawei.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1728203AbgK0IlN (ORCPT ); Fri, 27 Nov 2020 03:41:13 -0500 Received: from DGGEMS401-HUB.china.huawei.com (unknown [172.30.72.60]) by szxga07-in.huawei.com (SkyGuard) with ESMTP id 4Cj7PX5XSqz6vHL; Fri, 27 Nov 2020 16:40:48 +0800 (CST) Received: from localhost.localdomain (10.175.112.125) by DGGEMS401-HUB.china.huawei.com (10.3.19.201) with Microsoft SMTP Server id 14.3.487.0; Fri, 27 Nov 2020 16:41:07 +0800 From: Chen Huang To: Paul Walmsley , Palmer Dabbelt , Albert Ou CC: Andrew Morton , , Subject: [PATCH] riscv/stacktrace: fix stackframe without ra on the top Date: Fri, 27 Nov 2020 08:45:02 +0000 Message-ID: <20201127084502.2133722-1-chenhuang5@huawei.com> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 Content-Transfer-Encoding: 7BIT Content-Type: text/plain; charset=US-ASCII X-Originating-IP: [10.175.112.125] X-CFilter-Loop: Reflected Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org When a function doesn't have a callee, then it will not push ra into the stack, such as lkdtm_BUG() function: addi sp,sp,-16 sd s0,8(sp) addi s0,sp,16 ebreak Then we use pt_regs as a parameter to walk_stackframe(), for the struct stackframe use {fp,ra} to get information from stack, it will get the wrong value. And the call trace will be: [] lkdtm_BUG+0x6/0x8 ---[ end trace 18da3fbdf08e25d5 ]--- It should be that: [] lkdtm_BUG+0x6/0x8 [] lkdtm_do_action+0x14/0x1c [] direct_entry+0xc0/0x10a [] full_proxy_write+0x42/0x6a [] vfs_write+0x7e/0x214 [] ksys_write+0x98/0xc0 [] sys_write+0xe/0x16 [] ret_from_syscall+0x0/0x2 ---[ end trace 61917f3d9a9fadcd ]--- Signed-off-by: Chen Huang --- arch/riscv/kernel/stacktrace.c | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/arch/riscv/kernel/stacktrace.c b/arch/riscv/kernel/stacktrace.c index 595342910c3f..d1d4c18335c4 100644 --- a/arch/riscv/kernel/stacktrace.c +++ b/arch/riscv/kernel/stacktrace.c @@ -57,7 +57,14 @@ void notrace walk_stackframe(struct task_struct *task, struct pt_regs *regs, /* Unwind stack frame */ frame = (struct stackframe *)fp - 1; sp = fp; - fp = frame->fp; + if (regs && (frame->fp & 0x7) && (pc == regs->epc)) { + fp = frame->ra; + pc = regs->ra; + continue; + } else { + fp = frame->fp; + } + pc = ftrace_graph_ret_addr(current, NULL, frame->ra, (unsigned long *)(fp - 8)); } -- 2.17.1