From patchwork Tue Nov 23 19:37:19 2021 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Madhavan T. Venkataraman" X-Patchwork-Id: 12693496 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 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 smtp.lore.kernel.org (Postfix) with ESMTPS id 83A5FC433EF for ; Tue, 23 Nov 2021 19:39:23 +0000 (UTC) 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:MIME-Version:References:In-Reply-To: Message-Id:Date:Subject:To:From:Reply-To:Cc:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=IpngilX6Hk29vywWdJxQ4UIIiiQdI3TQMCywxELaIoE=; b=qRO19WzZ19fIiy vc8mdNqIgpvQsSWgdMGNcM7yHe7NK3+VSG0pXP4S3M1jCz5Qf5V9Cyi6bZ1kAtqYvcmMoRgFEMugF t8oiDWg5IbOw6xh0WOJq6LX/v40IBFz+MY/ah7yQ44hadw+weeAT/aZnUAbiTXzQYPMF8cpnYslz2 Zzej+uxFvC5B3YcS4hmMlfZ8WRvK6JsRzqDl0HSXCqeSsGohMQZy4+iLesfQ8khoU9oJCOIgy39QY 8gPCYeeEr00Gia+y4/Ovc5WzOymsX2bJCtUDeFODBU7QeUjwaNDvGS3iqwJFX8wH/7WqX3OMtg/4M VxUVupTV/rE109FAmv4g==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpbbo-003KQs-IS; Tue, 23 Nov 2021 19:37:40 +0000 Received: from linux.microsoft.com ([13.77.154.182]) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1mpbbk-003KOz-CL for linux-arm-kernel@lists.infradead.org; Tue, 23 Nov 2021 19:37:38 +0000 Received: from x64host.home (unknown [47.187.212.181]) by linux.microsoft.com (Postfix) with ESMTPSA id C5AF920D4D2F; Tue, 23 Nov 2021 11:37:33 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com C5AF920D4D2F DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1637696254; bh=aBWkrJAFXMJSS+1WUdBJpRlaPcIVMzXm3IBpam3uJ9Y=; h=From:To:Subject:Date:In-Reply-To:References:From; b=TJytDyRf37Fgz7JgNuv0WuLabLv1H8vkSUBnbEQgY7ZF6U4RwYZ4K+WJLUlurJcBf kiR9pf1NI5YpZWeq7VWjgM/YiVre44eCrIUi4PrE2mExPC+gLT16G8657dAPf70qad I+4Ze/ulCKeoNicrQuBaxlwLMUFlUGFD5t3VdTKk= From: madvenka@linux.microsoft.com To: mark.rutland@arm.com, 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, madvenka@linux.microsoft.com Subject: [PATCH v11 1/5] arm64: Call stack_backtrace() only from within walk_stackframe() Date: Tue, 23 Nov 2021 13:37:19 -0600 Message-Id: <20211123193723.12112-2-madvenka@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20211123193723.12112-1-madvenka@linux.microsoft.com> References: <8b861784d85a21a9bf08598938c11aff1b1249b9> <20211123193723.12112-1-madvenka@linux.microsoft.com> MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20211123_113736_514466_EAE9892F X-CRM114-Status: GOOD ( 13.77 ) 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 From: "Madhavan T. Venkataraman" Currently, arch_stack_walk() calls start_backtrace() and walk_stackframe() separately. There is no need to do that. Instead, call start_backtrace() from within walk_stackframe(). In other words, walk_stackframe() is the only unwind function a consumer needs to call. Currently, the only consumer is arch_stack_walk(). In the future, arch_stack_walk_reliable() will be another consumer. Currently, there is a check for a NULL task in unwind_frame(). It is not needed since all current consumers pass a non-NULL task. Use struct stackframe only within the unwind functions. Signed-off-by: Madhavan T. Venkataraman Reviewed-by: Mark Brown --- arch/arm64/kernel/stacktrace.c | 41 ++++++++++++++++++---------------- 1 file changed, 22 insertions(+), 19 deletions(-) diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 0fb58fed54cb..7217c4f63ef7 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -69,9 +69,6 @@ static int notrace unwind_frame(struct task_struct *tsk, unsigned long fp = frame->fp; struct stack_info info; - if (!tsk) - tsk = current; - /* Final frame; nothing to unwind */ if (fp == (unsigned long)task_pt_regs(tsk)->stackframe) return -ENOENT; @@ -143,15 +140,19 @@ static int notrace unwind_frame(struct task_struct *tsk, NOKPROBE_SYMBOL(unwind_frame); static void notrace walk_stackframe(struct task_struct *tsk, - struct stackframe *frame, + unsigned long fp, unsigned long pc, bool (*fn)(void *, unsigned long), void *data) { + struct stackframe frame; + + start_backtrace(&frame, fp, pc); + while (1) { int ret; - if (!fn(data, frame->pc)) + if (!fn(data, frame.pc)) break; - ret = unwind_frame(tsk, frame); + ret = unwind_frame(tsk, &frame); if (ret < 0) break; } @@ -195,17 +196,19 @@ noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry, void *cookie, struct task_struct *task, struct pt_regs *regs) { - struct stackframe frame; - - if (regs) - start_backtrace(&frame, regs->regs[29], regs->pc); - else if (task == current) - start_backtrace(&frame, - (unsigned long)__builtin_frame_address(1), - (unsigned long)__builtin_return_address(0)); - else - start_backtrace(&frame, thread_saved_fp(task), - thread_saved_pc(task)); - - walk_stackframe(task, &frame, consume_entry, cookie); + unsigned long fp, pc; + + if (regs) { + fp = regs->regs[29]; + pc = regs->pc; + } else if (task == current) { + /* Skip arch_stack_walk() in the stack trace. */ + fp = (unsigned long)__builtin_frame_address(1); + pc = (unsigned long)__builtin_return_address(0); + } else { + /* Caller guarantees that the task is not running. */ + fp = thread_saved_fp(task); + pc = thread_saved_pc(task); + } + walk_stackframe(task, fp, pc, consume_entry, cookie); }