From mboxrd@z Thu Jan 1 00:00:00 1970 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 8F096C4167B for ; Tue, 28 Nov 2023 10:30:59 +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:Message-ID:Date:References :In-Reply-To:Subject:Cc:To:From:Reply-To:Content-ID:Content-Description: Resent-Date:Resent-From:Resent-Sender:Resent-To:Resent-Cc:Resent-Message-ID: List-Owner; bh=wWffLUlDXf37I852/94xNJPn3yF+gE01M4IeAEz1HGM=; b=KVCfxx1XFdM4o8 4oB5WsZROVk2DvhtqdYOBU52rPR+uADpcDfgetlUE+B7jaSKaPiHBXVKCZQwXuzEsIJwijKjvh/IU wIEbfkjmv3YJwI/fWQFlPIkU7K8419SzPpyFs5FIqYwgvdtdpH6LK/aKH9VsFdnHOIotvzB0nNPue HFzkd27w1OOx4/zHktv+GbxmwyjARg0CIIZ9Q77+DonSAc3VAahULcoaU/+94kCZ3+oTGuiC02DAA oxtyFoZ2jyk/Ip3z9+P1i9D9Na+QrszQtoOXvTojvEqtHOzUFXk3Tt6kKtphxhNdIemiEKAYxyGU8 cS5VNw4+PrrDabJJAvZA==; Received: from localhost ([::1] helo=bombadil.infradead.org) by bombadil.infradead.org with esmtp (Exim 4.96 #2 (Red Hat Linux)) id 1r7vMk-004vji-2i; Tue, 28 Nov 2023 10:30:54 +0000 Received: from desiato.infradead.org ([2001:8b0:10b:1:d65d:64ff:fe57:4e05]) by bombadil.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r7uDb-004iKi-2w for linux-arm-kernel@bombadil.infradead.org; Tue, 28 Nov 2023 09:17:24 +0000 DKIM-Signature: v=1; a=rsa-sha256; q=dns/txt; c=relaxed/relaxed; d=infradead.org; s=desiato.20200630; h=Content-Type:MIME-Version:Message-ID: Date:References:In-Reply-To:Subject:Cc:To:From:Sender:Reply-To: Content-Transfer-Encoding:Content-ID:Content-Description; bh=R04CKhWa26PAZUsm1Mm9UYIr0LovubTV1L1tKEfAlBI=; b=hRxvGCszh9Bj0DG+NxY2jT2HcI ptmap9uah23W7sZ8sGYzpkQWYI9dkcoc0esluoa54LlmAN2r4qAA09l1CXiTj5mP7rMGWxbNg02Mf 0c0sxzKutqPyODCTo7EhEHMwUdeIhc1pbPcagRTNvI4vlmH9xod5Zh6sYqcMZ8osNpVTGPtu27TLk 5OPsfw7yh1F8RR9gA94mfSKA3k9rTWj2uYthNF5JcADpb19qIsB0PU03JfitzqCnL6TlXUdJv3kE7 gENDBPqcmiVEgdJGC2itTaM/xi8MKkTxr13WORCu8t265b7n8TrzhvofIWlZ/ZVBWV/6i6jjCX8Qn 8elO88aA==; Received: from mail-wm1-x332.google.com ([2a00:1450:4864:20::332]) by desiato.infradead.org with esmtps (Exim 4.96 #2 (Red Hat Linux)) id 1r7uDX-00GZGR-2E for linux-arm-kernel@lists.infradead.org; Tue, 28 Nov 2023 09:17:22 +0000 Received: by mail-wm1-x332.google.com with SMTP id 5b1f17b1804b1-40b2ad4953cso34779245e9.0 for ; Tue, 28 Nov 2023 01:17:18 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20230601; t=1701163037; x=1701767837; darn=lists.infradead.org; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:from:to:cc:subject:date:message-id:reply-to; bh=R04CKhWa26PAZUsm1Mm9UYIr0LovubTV1L1tKEfAlBI=; b=hvN44UhsENe4rMG99wS6dpxDa2PZXOV1N0CUAmHkcIXoZwuZnB9006lIwl399wmtNC OA7ighqfet7v8Y9XsKhKun5m49YCwZx0B7EV+JDxxGEFmvUjTX7FXGQiNWUH9/2izndk +x7Y9CcNc+J5H6oM9lOrGx7Zv4YI1YVA4AfjqimuyHwkaYn3M71poabBTeGWG2rb2hKa cFfregUn7GmZwIYje0VxRrWMMYNybmgi6cHMTnh2XmI0YiS/hVjBMoixo6bogyJchkXa hu6EZWbzU7PoVkdHo+cKA0dcRy1Hs5o/auiOs8Q58mBgwHEoQF0gBq56U4b+xbV0j7Vb vWug== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20230601; t=1701163037; x=1701767837; h=mime-version:message-id:date:references:in-reply-to:subject:cc:to :from:x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=R04CKhWa26PAZUsm1Mm9UYIr0LovubTV1L1tKEfAlBI=; b=CdtNYBvRIbykR1y6FG+TXw4f99rLGg/NcVvxmm5jcpSV5Iq9PcwrjrKY4Ahk/xPSzk yw870bcyfbS+HSS2B7dMKnPMefxsFPEasaMATfZ2T12DwacDVJIoXpu8YVVo3XvyCPwh UGs+rZWwVjYnkLkOCrRi97gVT0jMpAusyuUIcM3Tr8siWEnbgyYOnjfJIeL4dvczngPz YwtW+xWFoAgn0ZPj0nk/VMFY/ak3YIvlYUwkotv7nOpZk+ssEHexy3NgUZeDC0u3Y1p6 /A/HEtdDZH44qlJwfU4QcdkvoEDySJeR2PUJprHo0Wxr36JvGj2rVxB+2l3a3Wq/qZqa RKXg== X-Gm-Message-State: AOJu0YwxeyVZ3ZrIS7AYf1ZUufqY88xElFM2UoRFlLrNmNBA6Kzi2grh fbIZxTFTxHbmBwI5rg/aGlg= X-Google-Smtp-Source: AGHT+IHJWfthDLpN2MJMm59H1saPeU3vQ5eI07iO7jJfMlr9kKoAffchX1/18ipb7k0RyPrnjF7WeQ== X-Received: by 2002:a05:600c:4fc6:b0:408:411c:4f6d with SMTP id o6-20020a05600c4fc600b00408411c4f6dmr11979553wmq.14.1701163036994; Tue, 28 Nov 2023 01:17:16 -0800 (PST) Received: from localhost (54-240-197-231.amazon.com. [54.240.197.231]) by smtp.gmail.com with ESMTPSA id m5-20020a5d56c5000000b00332cbd59f8bsm14330101wrw.25.2023.11.28.01.17.16 (version=TLS1_2 cipher=ECDHE-ECDSA-AES128-GCM-SHA256 bits=128/128); Tue, 28 Nov 2023 01:17:16 -0800 (PST) From: Puranjay Mohan To: Mark Rutland , linux-arm-kernel@lists.infradead.org Cc: broonie@kernel.org, catalin.marinas@arm.com, kaleshsingh@google.com, madvenka@linux.microsoft.com, mark.rutland@arm.com, will@kernel.org Subject: Re: [PATCH 2/2] arm64: stacktrace: factor out kunwind_stack_walk() In-Reply-To: <20231124110511.2795958-3-mark.rutland@arm.com> References: <20231124110511.2795958-1-mark.rutland@arm.com> <20231124110511.2795958-3-mark.rutland@arm.com> Date: Tue, 28 Nov 2023 09:17:13 +0000 Message-ID: MIME-Version: 1.0 X-CRM114-Version: 20100106-BlameMichelson ( TRE 0.8.0 (BSD) ) MR-646709E3 X-CRM114-CacheID: sfid-20231128_091719_999807_99A279CC X-CRM114-Status: GOOD ( 26.27 ) 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: , Content-Type: text/plain; charset="us-ascii" Content-Transfer-Encoding: 7bit Sender: "linux-arm-kernel" Errors-To: linux-arm-kernel-bounces+linux-arm-kernel=archiver.kernel.org@lists.infradead.org Mark Rutland writes: > Currently arm64 uses the generic arch_stack_walk() interface for all > stack walking code. This only passes a PC value and cookie to the unwind > callback, whereas we'd like to pass some additional information in some > cases. For example, the BPF exception unwinder wants the FP, for > reliable stacktrace we'll want to perform additional checks on other > portions of unwind state, and we'd like to expand the information > printed by dump_backtrace() to include provenance and reliability > information. > > As preparation for all of the above, this patch factors the core unwind > logic out of arch_stack_walk() and into a new kunwind_stack_walk() > function which provides all of the unwind state to a callback function. > The existing arch_stack_walk() interface is implemented atop this. > > The kunwind_stack_walk() function is intended to be a private > implementation detail of unwinders in stacktrace.c, and not something to > be exported generally to kernel code. It is __always_inline'd into its > caller so that neither it or its caller appear in stactraces (which is > the existing/required behavior for arch_stack_walk() and friends) and so > that the compiler can optimize away some of the indirection. > > There should be no functional change as a result of this patch. > Thanks for helping with this. Reviewed-by: Puranjay Mohan Thanks, Puranjay > Signed-off-by: Mark Rutland > Cc: Catalin Marinas > Cc: Kalesh Singh > Cc: Madhavan T. Venkataraman > Cc: Mark Brown > Cc: Puranjay Mohan > Cc: Will Deacon > --- > arch/arm64/kernel/stacktrace.c | 39 ++++++++++++++++++++++++++++------ > 1 file changed, 33 insertions(+), 6 deletions(-) > > diff --git a/arch/arm64/kernel/stacktrace.c b/arch/arm64/kernel/stacktrace.c > index aafc89192787a..7f88028a00c02 100644 > --- a/arch/arm64/kernel/stacktrace.c > +++ b/arch/arm64/kernel/stacktrace.c > @@ -154,8 +154,10 @@ kunwind_next(struct kunwind_state *state) > return kunwind_recover_return_address(state); > } > > +typedef bool (*kunwind_consume_fn)(const struct kunwind_state *state, void *cookie); > + > static __always_inline void > -do_kunwind(struct kunwind_state *state, stack_trace_consume_fn consume_entry, > +do_kunwind(struct kunwind_state *state, kunwind_consume_fn consume_state, > void *cookie) > { > if (kunwind_recover_return_address(state)) > @@ -164,7 +166,7 @@ do_kunwind(struct kunwind_state *state, stack_trace_consume_fn consume_entry, > while (1) { > int ret; > > - if (!consume_entry(cookie, state->common.pc)) > + if (!consume_state(state, cookie)) > break; > ret = kunwind_next(state); > if (ret < 0) > @@ -201,9 +203,10 @@ do_kunwind(struct kunwind_state *state, stack_trace_consume_fn consume_entry, > : stackinfo_get_unknown(); \ > }) > > -noinline noinstr void arch_stack_walk(stack_trace_consume_fn consume_entry, > - void *cookie, struct task_struct *task, > - struct pt_regs *regs) > +static __always_inline void > +kunwind_stack_walk(kunwind_consume_fn consume_state, > + void *cookie, struct task_struct *task, > + struct pt_regs *regs) > { > struct stack_info stacks[] = { > stackinfo_get_task(task), > @@ -236,7 +239,31 @@ noinline noinstr void arch_stack_walk(stack_trace_consume_fn consume_entry, > kunwind_init_from_task(&state, task); > } > > - do_kunwind(&state, consume_entry, cookie); > + do_kunwind(&state, consume_state, cookie); > +} > + > +struct kunwind_consume_entry_data { > + stack_trace_consume_fn consume_entry; > + void *cookie; > +}; > + > +static bool > +arch_kunwind_consume_entry(const struct kunwind_state *state, void *cookie) > +{ > + struct kunwind_consume_entry_data *data = cookie; > + return data->consume_entry(data->cookie, state->common.pc); > +} > + > +noinline noinstr void arch_stack_walk(stack_trace_consume_fn consume_entry, > + void *cookie, struct task_struct *task, > + struct pt_regs *regs) > +{ > + struct kunwind_consume_entry_data data = { > + .consume_entry = consume_entry, > + .cookie = cookie, > + }; > + > + kunwind_stack_walk(arch_kunwind_consume_entry, &data, task, regs); > } > > static bool dump_backtrace_entry(void *arg, unsigned long where) > -- > 2.30.2 _______________________________________________ linux-arm-kernel mailing list linux-arm-kernel@lists.infradead.org http://lists.infradead.org/mailman/listinfo/linux-arm-kernel