From patchwork Thu May 18 11:08:03 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: tip-bot2 for Thomas Gleixner X-Patchwork-Id: 95789 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp410003vqo; Thu, 18 May 2023 04:15:55 -0700 (PDT) X-Google-Smtp-Source: ACHHUZ5T8blQZ6E/TD+npsixTvPNtWtloRN0vzsVF+ezw+DlepiihuZDXvk4nVNebEQK1dMqcV3d X-Received: by 2002:a17:90a:578c:b0:253:40dd:52d2 with SMTP id g12-20020a17090a578c00b0025340dd52d2mr2281512pji.10.1684408555089; Thu, 18 May 2023 04:15:55 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1684408555; cv=none; d=google.com; s=arc-20160816; b=b5MS6azCz+B0MxBZw2iMSDTH0HIKH650DcnGfs86sivlLKx4ye2OPuoRU8dxhfDASa xUGHbYLhSKtrjXV9qi/bPin74P7OMOHzIbZCGEGVCsTYzzXGtyqAaDEyaOCn9MfsvydS hfVTtffPAIaAZV+oCHF7w4Dh/wtTiPxrQcGaupqiETSLT/9BfRbl3COb2taCxocLxetP PeTbxBc2xPDM8jYGMolWXWh1Ez5/xEpoa3NL8aMcKW9Ua7U6zxe9CFs21T0iAyb/025T 8bpx/Go8oVi31J2lpPgExpVpZT6cVP9P7V+sTN+vdQ4EfYNaOGVyRhN5P1sZjc6aPNvk PZRg== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:robot-unsubscribe :robot-id:message-id:mime-version:references:in-reply-to:cc:subject :to:reply-to:sender:from:dkim-signature:dkim-signature:date; bh=5ejN/mH3LR4t0/RUCezt3x65qUEpqLMlgQXY4nbjFu8=; b=SgbRYwxH/EqxAZaXok72LcK0SGXzh/5cfarKjE1FYvX8fsqeojWte0ZAvVn1fdBG7t g8iGnFXCKDVZl8C0IHLbipFDEAV2E8X2mpxRZCui81r/eXIY1DP84Zv8DkCohKooNCci xQt4+eX/CmEhzg92bd21a1RqJfOSS4+JSevOgQJHhPnx4ulomqewXb5lI0ZIjv+GpwCw 41pC12CaTBKG1D11UIHbAdi6OuHzWagsqnDS3Th+EwlJgMJHs/Bv8oRhIURwsR+fn7qp hXEbtMmoAcJ+wod3VvksHMPrRL+ODUeYR45LrmdntDsNx754hHkS7rfHRxbhR+5qSYIU FsLg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@linutronix.de header.s=2020 header.b=XC6eLNNs; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id b198-20020a6334cf000000b0052c8234a858si1253871pga.168.2023.05.18.04.15.39; Thu, 18 May 2023 04:15:55 -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=@linutronix.de header.s=2020 header.b=XC6eLNNs; dkim=neutral (no key) header.i=@linutronix.de; 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=QUARANTINE dis=NONE) header.from=linutronix.de Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S231223AbjERLJ1 (ORCPT + 99 others); Thu, 18 May 2023 07:09:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43600 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231165AbjERLJS (ORCPT ); Thu, 18 May 2023 07:09:18 -0400 Received: from galois.linutronix.de (Galois.linutronix.de [193.142.43.55]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D3FE8213B; Thu, 18 May 2023 04:08:36 -0700 (PDT) Date: Thu, 18 May 2023 11:08:03 -0000 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020; t=1684408083; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5ejN/mH3LR4t0/RUCezt3x65qUEpqLMlgQXY4nbjFu8=; b=XC6eLNNsAdHp2b1+A3c+pnQghTjEL3wVKhHYIY5YjHmAUd88GYRm6AG5WTglqeoArFVR2h UxivzU+HIJyIjwZvNlHpo06Bq2aw6vGRhtAzUPUtQjF7QB+iqVLR9RJRTPJyfbNhnUliFu hDqUlFpq+tT+xIZmZov+y1iKmkvpSSG9/bmWQGqzqPfFEkmhhKgcZuz3Cix7IW1nyXHQ+W gYinMFk1gCFu+z2f9th7ZoIvMcrHuQ10fopwSBPfMxQ3f81NTWZtwPnMC6RCWcCG3wlJCY zGgt9aQJaSedQdj8hMKaNa8OnehslekxEapqvhf32gRHvMWQu7RUxD50R6qYjg== DKIM-Signature: v=1; a=ed25519-sha256; c=relaxed/relaxed; d=linutronix.de; s=2020e; t=1684408083; h=from:from:sender:sender:reply-to:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references; bh=5ejN/mH3LR4t0/RUCezt3x65qUEpqLMlgQXY4nbjFu8=; b=51/M3jrukm/XcJMmtDuSZIBW9GG7Y57/BG1pVdiWYWKLgYj54RmbGam1WV0cPwlL7YbrgJ 4wLJdsY5DeCsEJBw== From: "tip-bot2 for Josh Poimboeuf" Sender: tip-bot2@linutronix.de Reply-to: linux-kernel@vger.kernel.org To: linux-tip-commits@vger.kernel.org Subject: [tip: objtool/core] x86/unwind/orc: Add 'unwind_debug' cmdline option Cc: Miroslav Benes , Josh Poimboeuf , x86@kernel.org, linux-kernel@vger.kernel.org In-Reply-To: <6afb9e48a05fd2046bfad47e69b061b43dfd0e0e.1681331449.git.jpoimboe@kernel.org> References: <6afb9e48a05fd2046bfad47e69b061b43dfd0e0e.1681331449.git.jpoimboe@kernel.org> MIME-Version: 1.0 Message-ID: <168440808334.404.13534074205868319070.tip-bot2@tip-bot2> Robot-ID: Robot-Unsubscribe: Contact to get blacklisted from these emails X-Spam-Status: No, score=-4.4 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_MED,SPF_HELO_NONE, SPF_PASS,T_SCC_BODY_TEXT_LINE 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 X-getmail-retrieved-from-mailbox: =?utf-8?q?INBOX?= X-GMAIL-THRID: =?utf-8?q?1763005909759872901?= X-GMAIL-MSGID: =?utf-8?q?1766230385144731983?= The following commit has been merged into the objtool/core branch of tip: Commit-ID: 89da5a69a831f20df6463fd524e1578e12a8f46f Gitweb: https://git.kernel.org/tip/89da5a69a831f20df6463fd524e1578e12a8f46f Author: Josh Poimboeuf AuthorDate: Wed, 12 Apr 2023 13:31:05 -07:00 Committer: Josh Poimboeuf CommitterDate: Tue, 16 May 2023 06:31:50 -07:00 x86/unwind/orc: Add 'unwind_debug' cmdline option 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. Reviewed-by: Miroslav Benes Link: https://lore.kernel.org/r/6afb9e48a05fd2046bfad47e69b061b43dfd0e0e.1681331449.git.jpoimboe@kernel.org Signed-off-by: Josh Poimboeuf --- Documentation/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/Documentation/admin-guide/kernel-parameters.txt index 9e5bab2..f922eea 100644 --- a/Documentation/admin-guide/kernel-parameters.txt +++ b/Documentation/admin-guide/kernel-parameters.txt @@ -6563,6 +6563,12 @@ unknown_nmi_panic [X86] Cause panic on unknown NMI. + 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= [USB] Default USB device authorization: (default -1 = authorized except for wireless USB, diff --git a/arch/x86/kernel/unwind_orc.c b/arch/x86/kernel/unwind_orc.c index 5fbcb22..7891727 100644 --- a/arch/x86/kernel/unwind_orc.c +++ b/arch/x86/kernel/unwind_orc.c @@ -13,8 +13,14 @@ #define orc_warn_current(args...) \ ({ \ - if (state->task == current && !state->error) \ + static bool dumped_before; \ + if (state->task == current && !state->error) { \ orc_warn(args); \ + if (unwind_debug && !dumped_before) { \ + dumped_before = true; \ + unwind_dump(state); \ + } \ + } \ }) extern int __start_orc_unwind_ip[]; @@ -23,8 +29,49 @@ extern struct orc_entry __start_orc_unwind[]; extern struct orc_entry __stop_orc_unwind[]; static bool orc_init __ro_after_init; +static bool unwind_debug __ro_after_init; static unsigned int lookup_num_blocks __ro_after_init; +static int __init unwind_debug_cmdline(char *str) +{ + unwind_debug = 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 = {0}; + unsigned long visit_mask = 0; + + if (dumped_before) + return; + + dumped_before = 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 = __builtin_frame_address(0); sp; + sp = 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 = 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;