From nobody Thu Feb 12 00:27:48 2026 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 vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 50F07C77B6E for ; Wed, 12 Apr 2023 20:31:18 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230128AbjDLUbQ (ORCPT ); Wed, 12 Apr 2023 16:31:16 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:45674 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229630AbjDLUbO (ORCPT ); Wed, 12 Apr 2023 16:31:14 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [139.178.84.217]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 6B522114 for ; Wed, 12 Apr 2023 13:31:13 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by dfw.source.kernel.org (Postfix) with ESMTPS id 07AAB63911 for ; Wed, 12 Apr 2023 20:31:13 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 32FEDC433EF; Wed, 12 Apr 2023 20:31:12 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1681331472; bh=8GhW4AZ4NxnljR80VEjsxcBXtn1G+kAae3SO1+2smj8=; h=From:To:Cc:Subject:Date:From; b=kOeueKX/ojHULbe/OAn33tWHUyiznA4fa4jpuvvFRzcivr/9P2SnKR8yrILtGpQqR kt8kMhBN0bMH0REcxm2bItuuZr5c7XlIydCJfp1M+Dgsm9zItqSQua6RWjkvOkYcSh G5OjH9lGtvLVhd+A44kIlYzmIi7i2QBT3GJgMal/8toKGRgEOB6eO+WAMpFUimPTzY Oc8w7fXdEh1QJyAMaIDfD2zzL9ltNeoeKayZT/cCYerLVIx/6fjjgqzwzmw6bRaV0Z EKzW4DkK2rZBuT65SVox3ED8AQQeTh5MRQHUCdx1Kvll/Px0MfxLW5vdk7xrN3do3X ktjsgWdWJJZNA== From: Josh Poimboeuf To: x86@kernel.org Cc: linux-kernel@vger.kernel.org, Peter Zijlstra , Miroslav Benes , Josh Poimboeuf Subject: [PATCH] x86/unwind/orc: Add 'unwind_debug' cmdline option Date: Wed, 12 Apr 2023 13:31:05 -0700 Message-Id: <6afb9e48a05fd2046bfad47e69b061b43dfd0e0e.1681331449.git.jpoimboe@kernel.org> X-Mailer: git-send-email 2.39.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org Content-Type: text/plain; charset="utf-8" From: Josh Poimboeuf Sometimes the one-line ORC unwinder warnings aren't very helpful. Add a new 'unwind_debug' cmdline option which will dump the full stack contents of the current task when an error condition is encountered. Signed-off-by: Josh Poimboeuf Reviewed-by: Miroslav Benes Signed-off-by: Josh Poimboeuf --- .../admin-guide/kernel-parameters.txt | 6 +++ arch/x86/kernel/unwind_orc.c | 49 ++++++++++++++++++- 2 files changed, 54 insertions(+), 1 deletion(-) diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentatio= n/admin-guide/kernel-parameters.txt index 6221a1d057dd..60838db8c663 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6530,6 +6530,12 @@ unknown_nmi_panic [X86] Cause panic on unknown NMI. =20 + unwind_debug [X86-64] + Enable unwinder debug output. This can be + useful for debugging certain unwinder error + conditions, including corrupt stacks and + bad/missing unwinder metadata. + usbcore.authorized_default=3D [USB] Default USB device authorization: (default -1 =3D authorized except for wireless USB, diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c index 5fbcb229f707..7891727f534e 100644 --- a/arch/x86/kernel/unwind_orc.c +++ b/arch/x86/kernel/unwind_orc.c @@ -13,8 +13,14 @@ =20 #define orc_warn_current(args...) \ ({ \ - if (state->task =3D=3D current && !state->error) \ + static bool dumped_before; \ + if (state->task =3D=3D current && !state->error) { \ orc_warn(args); \ + if (unwind_debug && !dumped_before) { \ + dumped_before =3D true; \ + unwind_dump(state); \ + } \ + } \ }) =20 extern int __start_orc_unwind_ip[]; @@ -23,8 +29,49 @@ extern struct orc_entry __start_orc_unwind[]; extern struct orc_entry __stop_orc_unwind[]; =20 static bool orc_init __ro_after_init; +static bool unwind_debug __ro_after_init; static unsigned int lookup_num_blocks __ro_after_init; =20 +static int __init unwind_debug_cmdline(char *str) +{ + unwind_debug =3D true; + + return 0; +} +early_param("unwind_debug", unwind_debug_cmdline); + +static void unwind_dump(struct unwind_state *state) +{ + static bool dumped_before; + unsigned long word, *sp; + struct stack_info stack_info =3D {0}; + unsigned long visit_mask =3D 0; + + if (dumped_before) + return; + + dumped_before =3D true; + + printk_deferred("unwind stack type:%d next_sp:%p mask:0x%lx graph_idx:%d\= n", + state->stack_info.type, state->stack_info.next_sp, + state->stack_mask, state->graph_idx); + + for (sp =3D __builtin_frame_address(0); sp; + sp =3D PTR_ALIGN(stack_info.next_sp, sizeof(long))) { + if (get_stack_info(sp, state->task, &stack_info, &visit_mask)) + break; + + for (; sp < stack_info.end; sp++) { + + word =3D READ_ONCE_NOCHECK(*sp); + + printk_deferred("%0*lx: %0*lx (%pB)\n", BITS_PER_LONG/4, + (unsigned long)sp, BITS_PER_LONG/4, + word, (void *)word); + } + } +} + static inline unsigned long orc_ip(const int *ip) { return (unsigned long)ip + *ip; --=20 2.39.2