From patchwork Thu Apr 29 01:43:21 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Leo Yan X-Patchwork-Id: 12230319 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org X-Spam-Level: X-Spam-Status: No, score=-17.0 required=3.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,HEADER_FROM_DIFFERENT_DOMAINS,INCLUDES_CR_TRAILER, INCLUDES_PATCH,MAILING_LIST_MULTI,SPF_HELO_NONE,SPF_PASS,URIBL_BLOCKED, USER_AGENT_GIT autolearn=ham autolearn_force=no version=3.4.0 Received: from mail.kernel.org (mail.kernel.org [198.145.29.99]) by smtp.lore.kernel.org (Postfix) with ESMTP id 7D583C433B4 for ; Thu, 29 Apr 2021 01:45:45 +0000 (UTC) Received: from desiato.infradead.org (desiato.infradead.org [90.155.92.199]) (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 EE82261450 for ; Thu, 29 Apr 2021 01:45:44 +0000 (UTC) DMARC-Filter: OpenDMARC Filter v1.3.2 mail.kernel.org EE82261450 Authentication-Results: mail.kernel.org; dmarc=fail (p=none dis=none) header.from=linaro.org Authentication-Results: mail.kernel.org; spf=none smtp.mailfrom=linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=lists.infradead.org; s=desiato.20200630; h=Sender:Content-Transfer-Encoding :Content-Type:List-Subscribe:List-Help:List-Post:List-Archive: List-Unsubscribe:List-Id:MIME-Version:Message-Id:Date:Subject:Cc:To:From: Reply-To:Content-ID:Content-Description:Resent-Date:Resent-From:Resent-Sender :Resent-To:Resent-Cc:Resent-Message-ID:In-Reply-To:References:List-Owner; bh=zzuEnmTvl31J4h+M9YTX7zFMxaaFmDU3pB8HYJNnnjo=; b=Vq7EmbVREsbH3Go4oPAGN6CgJx 9b3x/Ri3PSzQwqKDQpSl10JHXg/5Yw+3dA4HKPfa7/syZNF/1w3fnPGEafBh4HnMQOQW2zR74V1sP 7KMj9twLABa+EvqRF1jbb1Nqkk2P/Oxo19xAHssFXBGKU/qMhcESmN3P2s93QTUE4BaD6pO+E/X03 o/2JaPo7nyZUxaGpaqJtBwhyHShqmrKkt6UJqpXCD6KfAobN2Mp6bSxqUwwRixSHYzDt2C8vl61vb vXbgDstfFdFBmQsyM1KTbz2oU1rZGr/QMGIo4dv3a4IV240GvIJfbu+4NgHnCJ81TeUMMkfgcc2I8 6G398h+w==; Received: from localhost ([::1] helo=desiato.infradead.org) by desiato.infradead.org with esmtp (Exim 4.94 #2 (Red Hat Linux)) id 1lbviW-004dpI-Jt; Thu, 29 Apr 2021 01:43:49 +0000 Received: from bombadil.infradead.org ([2607:7c80:54:e::133]) by desiato.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lbviM-004dor-Ja for linux-arm-kernel@desiato.infradead.org; Thu, 29 Apr 2021 01:43:42 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=bombadil.20210309; h=Content-Transfer-Encoding: MIME-Version:Message-Id:Date:Subject:Cc:To:From:Sender:Reply-To:Content-Type: Content-ID:Content-Description:In-Reply-To:References; bh=W4UwE2Dbwa47OkyVoSFrNDymke2/cl1Ry9ysp9qho4Q=; b=r32bUUfwQA8YdB259DgRw9xLPR hBTolp9LyfL/32fcQn0uvROnSoBB3jRjacFvuzTkZEzSPRROL+RBjbHZUHFx/Qk2WD40dDBi0QCBr +XQN+IRHWvIhxDJyA3qzPZATjI5C0Puy/mRYa/ierb+Qj3YCa+oaWrRrA4XZiZcyZR9MdJVdtDf9Z NR18KSkLTZOfO737RT5nf5tp+Kd08+/J3RsHsh1rTzOgu82xGJG3ly+WBNQHhXH5zN7kj/iIkRGvW 1voLZ1YduQSAjxX9uq3LGuoq/yrBMvbjJD/HWxxzElBiWl9FhsIhI2hsT+n0Ysr/aMgEP4kSra9p3 Nwh0QaUA==; Received: from mail-pf1-x42f.google.com ([2607:f8b0:4864:20::42f]) by bombadil.infradead.org with esmtps (Exim 4.94 #2 (Red Hat Linux)) id 1lbviK-000JZ7-1L for linux-arm-kernel@lists.infradead.org; Thu, 29 Apr 2021 01:43:37 +0000 Received: by mail-pf1-x42f.google.com with SMTP id c3so26249719pfo.3 for ; Wed, 28 Apr 2021 18:43:35 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linaro.org; s=google; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=W4UwE2Dbwa47OkyVoSFrNDymke2/cl1Ry9ysp9qho4Q=; b=wPkGlcF0955iBFFTsDYmWzReIFFILvyj3Xl9zQnh7GaknUyB4JiENrsp/rXfc+Yy+w WiqX3MN+IsYJZw4Gc3O5aUB658hl5UVck+EbetD0CdOIPGBIviL2QS/jmc+mCG3ejutf qqtZOYh1zAiEoV/yNlxFk6DrwoanvMo6vZqaicPk5om9J0eEvUVXt+6tpzpj8EzRBxlW f64AS4S4KPORiCRI8rcjV20PPruqh1YuYzdvWIR4CHksWpxRT0vf72UhyLaAO/UUiz+j puyBfKWzyO/U/SGwaZGdbgt0RH+Gl6N/CSCCsKcr31RVcAl2EjijJwRSfKWd+PdB98NN +P1Q== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=W4UwE2Dbwa47OkyVoSFrNDymke2/cl1Ry9ysp9qho4Q=; b=sD83YEH/qvFL+iVfCeHbh5rsm89RSu12kTZ6pYiBBqzKeuID0SMj2P2eREm+sLzdQJ PuqqtsNAA3G+XyGh85WjPDXeBWh42cimEVnJ1SsdzfX9X2wvb6K+zCFaloGHUEYNTn6L eXLXI39DHWwMlyyVJb06P/6O6scJzCol+A1t8GgwtKxbszhW0F4yl2aaMUfcoa3QThhU vp/pHeBOAzCpv+xPHuomcKXszCVzEgZ9NDdx/5KdfmN7Tusdo26g7LQTbYStvGalO86a 1KC7q5n4wV5H/h7LxvtpDsH9DVrqVel+fZ/sakUxJPnoOILV06T97ipeRTVkuwmhm8V7 ggtg== X-Gm-Message-State: AOAM5319lXxn2CRZt3jDZJjmIy96F2jbwgvFLNtRcXdt976/39SxNlG3 ho0PIhdi5UW5GNsssY74ixBnsg== X-Google-Smtp-Source: ABdhPJzmOB6NKYjVpqO6pigE8zHGwwDPUl3pMRk7roD7Cj4XxjhQ/7kOYTe6sgaayGF4i8Vm7yNbig== X-Received: by 2002:a62:8747:0:b029:27f:6a61:c742 with SMTP id i68-20020a6287470000b029027f6a61c742mr988846pfe.3.1619660614717; Wed, 28 Apr 2021 18:43:34 -0700 (PDT) Received: from localhost ([103.207.71.35]) by smtp.gmail.com with ESMTPSA id in1sm5776107pjb.23.2021.04.28.18.43.33 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 28 Apr 2021 18:43:34 -0700 (PDT) From: Leo Yan To: Catalin Marinas , Will Deacon , Mark Brown , Mark Rutland , Miroslav Benes , linux-arm-kernel@lists.infradead.org, linux-kernel@vger.kernel.org, Masami Hiramatsu Cc: Leo Yan Subject: [PATCH] arm64: stacktrace: Stop unwinding when the PC is zero Date: Thu, 29 Apr 2021 09:43:21 +0800 Message-Id: <20210429014321.196606-1-leo.yan@linaro.org> X-Mailer: git-send-email 2.25.1 MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20210428_184336_098112_A55266EE X-CRM114-Status: GOOD ( 14.53 ) 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: , Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org When use ftrace for stack trace, it reports the spurious frame with the PC value is zero. This can be reproduced with commands: # cd /sys/kernel/debug/tracing/ # echo "prev_pid == 0" > events/sched/sched_switch/filter # echo stacktrace > events/sched/sched_switch/trigger # echo 1 > events/sched/sched_switch/enable # cat trace -0 [005] d..2 259.621390: sched_switch: ... -0 [005] d..3 259.621394: => __schedule => schedule_idle => do_idle => cpu_startup_entry => secondary_start_kernel => 0 The kernel initializes FP/PC values as zero for swapper threads in head.S, when walk the stack frame, this patch stops unwinding if detect the PC value is zero, therefore can avoid the spurious frame. Below is the stacktrace after applying the change: # cat trace -0 [005] d..2 259.621390: sched_switch: ... -0 [005] d..3 259.621394: => __schedule => schedule_idle => do_idle => cpu_startup_entry => secondary_start_kernel Signed-off-by: Leo Yan Signed-off-by: Mark Rutland Reported-by: Leo Yan Tested-by: Leo Yan --- arch/arm64/kernel/stacktrace.c | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 84b676bcf867..02b1e85b2026 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -145,7 +145,11 @@ void notrace walk_stackframe(struct task_struct *tsk, struct stackframe *frame, if (!fn(data, frame->pc)) break; ret = unwind_frame(tsk, frame); - if (ret < 0) + /* + * When the frame->pc is zero, it has reached to the initial pc + * and fp values; stop unwinding for this case. + */ + if (ret < 0 || !frame->pc) break; } }