From patchwork Mon Jan 17 14:56:01 2022 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: "Madhavan T. Venkataraman" X-Patchwork-Id: 12715506 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 98592C433EF for ; Mon, 17 Jan 2022 14:58:40 +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=vVYn6puw4t0cFPCN55P8kBIyokPSrwb9+WtiSrxKOZg=; b=2uBqwHQ8w5dw5f LxiMFeBX2ppoAkLbfBybeB35rguKmSaPH5fgd706wme4T7U3CowDPBYo1raU6FSQLV7HZsBpgMubb 2DUjN+MY5HI8vyuWvV73YOKA0420RLenTwEcM31+bxo5nfguas1BqWMqWJRG/1C0HjHGzMJPVU6Wo g/561gUA5t90Cdwvdm/5K03jkTB0y7upn0Y6Fpdb1LsALnJp+iE+co9f2OZ1tXWz7FaWN2dFO2gaP 0Ua+lCFWkGMdok0M3pIGD6zCFB706iASVJ7QcJ/DKK6dtZqFevzKFT2CYmKEZsvvKUiSMIkG2X22J UzrLYEEuQJppEPk41TFg==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.94.2 #2 (Red Hat Linux)) id 1n9TRm-00FGhL-LF; Mon, 17 Jan 2022 14:57:26 +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 1n9TQq-00FGLa-UD for linux-arm-kernel@lists.infradead.org; Mon, 17 Jan 2022 14:56:31 +0000 Received: from x64host.home (unknown [47.187.212.181]) by linux.microsoft.com (Postfix) with ESMTPSA id E01FE20B9137; Mon, 17 Jan 2022 06:56:27 -0800 (PST) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com E01FE20B9137 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1642431388; bh=iltLKVcth/w3lsN6QiNX6zEGsWq02EiMywUsEzd+d2M=; h=From:To:Subject:Date:In-Reply-To:References:From; b=iWhhFPx637qzAF3ITigRhhH+CktW3lAtlGV+dBWjbpWnRabUxsnwV7e7QblUUF6L3 VenP3F4tnqMpYQslpDCFb3RmflP1hMfWQk0Kf5AJTBkOSpIIQpQJ41Io+9fuuuEKHU ahFGTNjGC6+b9sj7iq/VPMgOdynTd5luwbD/cKQk= 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 v13 04/11] arm64: Split unwind_init() Date: Mon, 17 Jan 2022 08:56:01 -0600 Message-Id: <20220117145608.6781-5-madvenka@linux.microsoft.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220117145608.6781-1-madvenka@linux.microsoft.com> References: <95691cae4f4504f33d0fc9075541b1e7deefe96f> <20220117145608.6781-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-20220117_065629_077022_F5A12609 X-CRM114-Status: GOOD ( 14.31 ) 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" 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_current() - 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 --- arch/arm64/kernel/stacktrace.c | 54 +++++++++++++++++++++++++++------- 1 file changed, 44 insertions(+), 10 deletions(-) diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c index a1a7ff93b84f..b2b568e5deba 100644 --- a/arch/arm64/kernel/stacktrace.c +++ b/arch/arm64/kernel/stacktrace.c @@ -33,11 +33,8 @@ */ -static 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 @@ -56,6 +53,46 @@ static void unwind_init(struct unwind_state *state, unsigned long fp, state->prev_type = STACK_TYPE_UNKNOWN; } +/* + * TODO: document requirements here. + */ +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; +} + +/* + * TODO: document requirements here. + * + * Note: this is always inlined, and we expect our caller to be a noinline + * function, such that this starts from our caller's caller. + */ +static __always_inline void unwind_init_from_current(struct unwind_state *state) +{ + unwind_init_common(state); + + state->fp = (unsigned long)__builtin_frame_address(1); + state->pc = (unsigned long)__builtin_return_address(0); +} + +/* + * TODO: document requirements here. + * + * The caller guarantees that the task is not running. + */ +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). * @@ -195,14 +232,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_current(&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); }