Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp816113iog; Fri, 17 Jun 2022 14:28:44 -0700 (PDT) X-Google-Smtp-Source: AGRyM1vaouo5I1h0s8H8Mx2Z5HLrT0UwrM91sWqbmz0w6fkzGuHORa0fiztreQ/I8yzzrPfe+8Pi X-Received: by 2002:a63:90c9:0:b0:3fc:f0c9:d0f with SMTP id a192-20020a6390c9000000b003fcf0c90d0fmr10563874pge.608.1655501324646; Fri, 17 Jun 2022 14:28:44 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655501324; cv=none; d=google.com; s=arc-20160816; b=D9RyrPtg3nbalmmoSlQd/RYW6mpqCBjJ1ALGuhG2h4KUzzp9IzW+cAdKSY0MSrG68e nRjMC0ESUCnbD0PR1UwxbuX4m7iCxvoFfATe25Q20U8i6hJzyh9zviMZv313201AjeJV +1eJ1hRbei+w2sml+W18JZeJQbPxMvsEnPwlwst0Xfk4D3rLf85BvKVKCrRQ0N0SOpb0 4ijQeG7A+RXhg84eqWKx4DCEJ8N6xewxQ2UW2eXIZ7+hB67sGw404QN7pLOrKXVi0hhq PIChO2lIVLVtgGZ7jxNLnAjKh5AFlYsjb1EHM/EP0v8Itdf1m7KfXcJBQSSKR3NErLh1 a8MA== 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=B6JQW5syKKdwir3NNZtlekEMoQqCcowRgtQfTpInk0w=; b=dqgYegz4ubdljtgdisy3lE0UNnaxeiHdlORxTjsPRnWXo6lpLZS2bI7IhbWbMCLpSb hBsmnA5ovhYLIAvsOEtiygULSpih3Gq0X2ZcrxD8yNa13Gn/20fB+RtELbonny59CVXx ToDh67ZKOUOvPjpTWNQvwr6MniRQp4uaJU9sfLfjEZthwzITcW/F7o0jZII7o94BguGh XMw31PpDbD3pNNGLCbXl4DwbvLqSGVboC8CYb96eKABOY9BQaYpd6WQ9wl/zf76Aq5wo 2V9LAJTUxIve6JNgT1pIFtW7udXJ1qKwZ8Sn9DiF7QMOi3VBhhXWuZ+guPHS75dH+nog Tqdw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=VpCrWXHJ; 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 h5-20020a635745000000b00408b7929729si6944098pgm.311.2022.06.17.14.28.33; Fri, 17 Jun 2022 14:28:44 -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=VpCrWXHJ; 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 S1383377AbiFQVH2 (ORCPT + 99 others); Fri, 17 Jun 2022 17:07:28 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40216 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231915AbiFQVH0 (ORCPT ); Fri, 17 Jun 2022 17:07:26 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 931FD5E15E; Fri, 17 Jun 2022 14:07:25 -0700 (PDT) Received: from x64host.home (unknown [47.189.24.195]) by linux.microsoft.com (Postfix) with ESMTPSA id 926FE20C343C; Fri, 17 Jun 2022 14:07:24 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 926FE20C343C DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1655500045; bh=B6JQW5syKKdwir3NNZtlekEMoQqCcowRgtQfTpInk0w=; h=From:To:Subject:Date:In-Reply-To:References:From; b=VpCrWXHJGeJXM/PALQDqlohLBAjitM9M3Dy7BRSG4S+7CL11c3dnSLlxLqSVyGj8j mZHQnso7nmMJ3tvtNuQ3OXKifNGFvcjIthgpw7bztSA5ftbmBtUkXmREbLkEBFLhrs UCd/7P+VbR8W3GECPY89uZVlqTaWNUjjaXgNHLS4= 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: [PATCH v15 1/6] arm64: Split unwind_init() Date: Fri, 17 Jun 2022 16:07:12 -0500 Message-Id: <20220617210717.27126-2-madvenka@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220617210717.27126-1-madvenka@linux.microsoft.com> References: <20220617210717.27126-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_FILL_THIS_FORM_SHORT,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" unwind_init() is currently a single function that initializes all of the unwind state. Split it into the following functions and call them appropriately: - unwind_init_from_regs() - initialize from regs passed by caller. - unwind_init_from_caller() - initialize for the current task from the caller of arch_stack_walk(). - unwind_init_from_task() - initialize from the saved state of a task other than the current task. In this case, the other task must not be running. This is done for two reasons: - the different ways of initializing are clear - specialized code can be added to each initializer in the future. Signed-off-by: Madhavan T. Venkataraman Reviewed-by: Mark Brown --- arch/arm64/kernel/stacktrace.c | 66 ++++++++++++++++++++++++++++------ 1 file changed, 55 insertions(+), 11 deletions(-) diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index 0467cb79f080..e44f93ff25f0 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -50,11 +50,8 @@ struct unwind_state { #endif }; -static notrace void unwind_init(struct unwind_state *state, unsigned long fp, - unsigned long pc) +static void unwind_init_common(struct unwind_state *state) { - state->fp = fp; - state->pc = pc; #ifdef CONFIG_KRETPROBES state->kr_cur = NULL; #endif @@ -72,7 +69,57 @@ static notrace void unwind_init(struct unwind_state *state, unsigned long fp, state->prev_fp = 0; state->prev_type = STACK_TYPE_UNKNOWN; } -NOKPROBE_SYMBOL(unwind_init); + +/* + * Start an unwind from a pt_regs. + * + * The unwind will begin at the PC within the regs. + * + * The regs must be on a stack currently owned by the calling task. + */ +static inline void unwind_init_from_regs(struct unwind_state *state, + struct pt_regs *regs) +{ + unwind_init_common(state); + + state->fp = regs->regs[29]; + state->pc = regs->pc; +} + +/* + * Start an unwind from a caller. + * + * The unwind will begin at the caller of whichever function this is inlined + * into. + * + * The function which invokes this must be noinline. + */ +static __always_inline void unwind_init_from_caller(struct unwind_state *state) +{ + unwind_init_common(state); + + state->fp = (unsigned long)__builtin_frame_address(1); + state->pc = (unsigned long)__builtin_return_address(0); +} + +/* + * Start an unwind from a blocked task. + * + * The unwind will begin at the blocked tasks saved PC (i.e. the caller of + * cpu_switch_to()). + * + * The caller should ensure the task is blocked in cpu_switch_to() for the + * duration of the unwind, or the unwind will be bogus. It is never valid to + * call this for the current task. + */ +static inline void unwind_init_from_task(struct unwind_state *state, + struct task_struct *task) +{ + unwind_init_common(state); + + state->fp = thread_saved_fp(task); + state->pc = thread_saved_pc(task); +} /* * Unwind from one frame record (A) to the next frame record (B). @@ -213,14 +260,11 @@ noinline notrace void arch_stack_walk(stack_trace_consume_fn consume_entry, struct unwind_state state; if (regs) - unwind_init(&state, regs->regs[29], regs->pc); + unwind_init_from_regs(&state, regs); else if (task == current) - unwind_init(&state, - (unsigned long)__builtin_frame_address(1), - (unsigned long)__builtin_return_address(0)); + unwind_init_from_caller(&state); else - unwind_init(&state, thread_saved_fp(task), - thread_saved_pc(task)); + unwind_init_from_task(&state, task); unwind(task, &state, consume_entry, cookie); } -- 2.25.1