Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp679569iog; Fri, 17 Jun 2022 11:05:36 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tez3IjG1oR9rvkcJn6U7esbzQCieo+y/YY130OJYbCE42OWtPFA5dGLGxjI35IcZ7sYVso X-Received: by 2002:a17:90a:fb93:b0:1e8:a809:af4d with SMTP id cp19-20020a17090afb9300b001e8a809af4dmr11925431pjb.7.1655489136233; Fri, 17 Jun 2022 11:05:36 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655489136; cv=none; d=google.com; s=arc-20160816; b=Co81bzzi216JEhuu6DD67WRHq/FaaZ/sgQPHcr48dH66GLS0NwkdEgnb4+H2nqKWGO MNzr/cXrkZuMJV7k0h78433+oD5zzfmw2ivY266O79LiMtTkpegwpNmhxYWoytXdWKDg fHiBwRPxPTkBxMw4jfmdzvIVrdjEgJB6bwYFfxGZySOHQ11YbCkwlbRnaG6CNXVw6QuT e45pGLb/dXu+NXe82EB3Ih0Msg8CTD/m/Y2kRY4jtfPDoSRz2cyFWgfUmwld3DwUC0Y5 qfikVC5Pcyzt/+Vw6g+W2WgeAIOoG4iI8VD2hq2FJxmJArqO33haqnbddVChpCP0fwjs kNUQ== 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=k1boHzoy4jG18Ef5Pcpah5H9f/WtsFu8a8F3NQVZFbRo+wZ7oxmSdrOJiNoyrp4/+u FAfW8iKxCk1AnG8DHqAJhHEDanJgasCNgSkfR3Dx8MsgIaiGsx/2mLyiFd05OSX+VJ2F kxMQsy2cKy0x51FTWtiJizKiSWSmrWdzzv8rcydJ/H3FDnBzX0lohyywxrgmamsKHeXV iEaI+JqdyvjbrHS8xHpZoWP+nmAoId39w7dwue2yX5u4P3+jCAyTpoyVe2G0tzRP1lqL LSGiVkgYXIgtLkTEyAhxxDQ3RAHE0T3Zx4hrRDhSk+gXBRBQeenMkNTKHMtYsEqIzK1d SHRw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linux.microsoft.com header.s=default header.b=ksoyPAkw; 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 e9-20020a63f549000000b003fc74f8624csi6631709pgk.178.2022.06.17.11.05.23; Fri, 17 Jun 2022 11:05:36 -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=ksoyPAkw; 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 S1383443AbiFQSCd (ORCPT + 99 others); Fri, 17 Jun 2022 14:02:33 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37324 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231433AbiFQSCc (ORCPT ); Fri, 17 Jun 2022 14:02:32 -0400 Received: from linux.microsoft.com (linux.microsoft.com [13.77.154.182]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id 4790650E34; Fri, 17 Jun 2022 11:02:31 -0700 (PDT) Received: from x64host.home (unknown [47.189.24.195]) by linux.microsoft.com (Postfix) with ESMTPSA id 4250520C3485; Fri, 17 Jun 2022 11:02:30 -0700 (PDT) DKIM-Filter: OpenDKIM Filter v2.11.0 linux.microsoft.com 4250520C3485 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linux.microsoft.com; s=default; t=1655488951; bh=B6JQW5syKKdwir3NNZtlekEMoQqCcowRgtQfTpInk0w=; h=From:To:Subject:Date:In-Reply-To:References:From; b=ksoyPAkw3LGpTdDkmOps8iqAPDDD+Eot4jXL22DnxuAUYWXgCqG6eRk4m/qHpggXS Bma/h2bi3mf14gy7o/U60H50AnX54cxB/O2OwkJWnHMDzsOEnF9aHk93YusbqQtswN 2dvFsQX9dA1Zgc4OrJoIXXfhzLUHGvAnpzn1NjYI= 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 1/6] arm64: Split unwind_init() Date: Fri, 17 Jun 2022 13:02:14 -0500 Message-Id: <20220617180219.20352-2-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_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