Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp680521iog; Fri, 17 Jun 2022 11:06:20 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vPEHvVKKFeX27N6OxTaCBci2sMCqo/kMpz/NJsp7Nn/ebjfvD6StDzBQM2SPe+RzuHCtGQ X-Received: by 2002:a17:90b:1bd0:b0:1e8:9ac9:c3ec with SMTP id oa16-20020a17090b1bd000b001e89ac9c3ecmr11924455pjb.117.1655489168916; Fri, 17 Jun 2022 11:06:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655489168; cv=none; d=google.com; s=arc-20160816; b=unSBoJ/3uN2K/JdvhEe/FMDFV8lbzkLk7OBwDIDUIYhfeXXP5hKKDWknlTNcD2GWbY wIka9kcgGQ48kVJWJLsaEwYPmsmfazygzV6irgiUeK8yWpsev2w2ETCGuX8tR8NfO4zE jz8/HrLksEZ9hN9IKlcW/Vg48r3o0kaohlzYdHOmbSeK9aZa2dpXqwDEEQPaYLwwv634 /AytkNenDyLXYhsNiUzozjomOiB1jylNI1zt01lZMVxMswgqy3eWDLN4eGDlmUwnifa8 NZ1VSh8R8rcmawnk6yv51g5r26s09P/gD2Gem/TEgc7HphiltFFd47Jg2HvHQFA2Yohz wzpQ== 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 :references:in-reply-to:message-id:date:subject:to:from :dkim-signature:dkim-filter; bh=4OYwsLak9eV14Lqr9wB+riHSEW5S0byajhIbP13YtuM=; b=c/ftJd2vs1VC6R/sbhyA8NcMOrrYqhzPMLBLAJXpFMr/OxKr5K/SPIOUGgWZSZfVwL Hehy4EAmAHehcqgIDYrdtl6F66GOvWWFDmwLUvBxkRJOFmaHNaqA5FvrjdL27jVNMPNs Wf/lyr6dy3zFcNQt3NA1WjUxo+Z0B5lN07MwwVnb5+7+L8kvjLn7P7gJaSu1PcsUoXa+ qyBeGigd3VKxLFpMbVGtvVKqgRLfXLFGvuMJU5HTdGvf+mvAQ8FyIXMHV8G3GwCuKLLX wc8AP/yCnpmemIshw+AKLPCvNahm+Td0UcCllmpWo65nI7TblD6KtmTb3FVPfetPrq3d +vpg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="AyvnqnH/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id u64-20020a637943000000b003fc19a6451esi6710228pgc.775.2022.06.17.11.05.55; Fri, 17 Jun 2022 11:06:08 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b="AyvnqnH/"; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=linux.microsoft.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1383428AbiFQSCv (ORCPT + 99 others); Fri, 17 Jun 2022 14:02:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37602 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1383462AbiFQSCo (ORCPT ); Fri, 17 Jun 2022 14:02:44 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 43D4D13F; Fri, 17 Jun 2022 11:02:32 -0700 (PDT) Received: from x64host.home (unknown [47.189.24.195]) by linux.microsoft.com (Postfix) with ESMTPSA id 3E52F20C348B; Fri, 17 Jun 2022 11:02:31 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 3E52F20C348B DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1655488952; bh=4OYwsLak9eV14Lqr9wB+riHSEW5S0byajhIbP13YtuM=; h=From:To:Subject:Date:In-Reply-To:References:From; b=AyvnqnH/jC9zfFIZFQQ+t8pH9dZHICIirEq7nxYP34Rmi+nCJ12zIdJ0w63twacyR qhlxKJRo7bx0nDxcvq0tPSqaV6vHglnh5O/G83URj4RpIijXQlBbzbaXljD0bHXa39 RlTK7jp1XSn4Ea5y6ILSYfpyMiNSHOwHsmGTsmvI= From: madvenka@linux.microsoft.com To: broonie@kernel.org, mark.rutland@arm.com, jpoimboe@redhat.com, ardb@kernel.org, nobuta.keiya@fujitsu.com, sjitindarsingh@gmail.com, catalin.marinas@arm.com, will@kernel.org, jamorris@linux.microsoft.com, linux-arm-kernel@lists.infradead.org, live-patching@vger.kernel.org, linux-kernel@vger.kernel.org, madvenka@linux.microsoft.com Subject: [RFC PATCH v15 2/6] arm64: Copy the task argument to unwind_state Date: Fri, 17 Jun 2022 13:02:15 -0500 Message-Id: <20220617180219.20352-3-madvenka@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220617180219.20352-1-madvenka@linux.microsoft.com> References: <20220617180219.20352-1-madvenka@linux.microsoft.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-19.8 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,ENV_AND_HDR_SPF_MATCH,RCVD_IN_DNSWL_MED, SPF_HELO_PASS,SPF_PASS,T_SCC_BODY_TEXT_LINE,USER_IN_DEF_DKIM_WL, USER_IN_DEF_SPF_WL autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: "Madhavan T. Venkataraman" Copy the task argument passed to arch_stack_walk() to unwind_state so that it can be passed to unwind functions via unwind_state rather than as a separate argument. The task is a fundamental part of the unwind state. Signed-off-by: Madhavan T. Venkataraman Reviewed-by: Mark Brown --- arch/arm64/kernel/stacktrace.c | 33 ++++++++++++++++++++------------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index e44f93ff25f0..8e43444d50e2 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -38,6 +38,8 @@ * @kr_cur: When KRETPROBES is selected, holds the kretprobe instance * associated with the most recently encountered replacement lr * value. + * + * @task: The task being unwound. */ struct unwind_state { unsigned long fp; @@ -48,10 +50,13 @@ struct unwind_state { #ifdef CONFIG_KRETPROBES struct llist_node *kr_cur; #endif + struct task_struct *task; }; -static void unwind_init_common(struct unwind_state *state) +static void unwind_init_common(struct unwind_state *state, + struct task_struct *task) { + state->task = task; #ifdef CONFIG_KRETPROBES state->kr_cur = NULL; #endif @@ -80,7 +85,7 @@ static void unwind_init_common(struct unwind_state *state) static inline void unwind_init_from_regs(struct unwind_state *state, struct pt_regs *regs) { - unwind_init_common(state); + unwind_init_common(state, current); state->fp = regs->regs[29]; state->pc = regs->pc; @@ -96,7 +101,7 @@ static inline void unwind_init_from_regs(struct unwind_state *state, */ static __always_inline void unwind_init_from_caller(struct unwind_state *state) { - unwind_init_common(state); + unwind_init_common(state, current); state->fp = (unsigned long)__builtin_frame_address(1); state->pc = (unsigned long)__builtin_return_address(0); @@ -115,7 +120,7 @@ static __always_inline void unwind_init_from_caller(struct unwind_state *state) static inline void unwind_init_from_task(struct unwind_state *state, struct task_struct *task) { - unwind_init_common(state); + unwind_init_common(state, task); state->fp = thread_saved_fp(task); state->pc = thread_saved_pc(task); @@ -128,9 +133,9 @@ static inline void unwind_init_from_task(struct unwind_state *state, * records (e.g. a cycle), determined based on the location and fp value of A * and the location (but not the fp value) of B. */ -static int notrace unwind_next(struct task_struct *tsk, - struct unwind_state *state) +static int notrace unwind_next(struct unwind_state *state) { + struct task_struct *tsk = state->task; unsigned long fp = state->fp; struct stack_info info; @@ -204,8 +209,7 @@ static int notrace unwind_next(struct task_struct *tsk, } NOKPROBE_SYMBOL(unwind_next); -static void notrace unwind(struct task_struct *tsk, - struct unwind_state *state, +static void notrace unwind(struct unwind_state *state, stack_trace_consume_fn consume_entry, void *cookie) { while (1) { @@ -213,7 +217,7 @@ static void notrace unwind(struct task_struct *tsk, if (!consume_entry(cookie, state->pc)) break; - ret = unwind_next(tsk, state); + ret = unwind_next(state); if (ret < 0) break; } @@ -259,12 +263,15 @@ noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry, { struct unwind_state state; - if (regs) + if (regs) { + if (task != current) + return; unwind_init_from_regs(&state, regs); - else if (task == current) + } else if (task == current) { unwind_init_from_caller(&state); - else + } else { unwind_init_from_task(&state, task); + } - unwind(task, &state, consume_entry, cookie); + unwind(&state, consume_entry, cookie); } -- 2.25.1