Received: by 2002:a05:6358:4e97:b0:b3:742d:4702 with SMTP id ce23csp2392128rwb; Mon, 15 Aug 2022 04:49:17 -0700 (PDT) X-Google-Smtp-Source: AA6agR582nN/gU8awBRVoSY//tQVjJNNvoxobX2I5oqgfWu1OwMJVDFba18d3kGOaSS6hNEQomhW X-Received: by 2002:a17:906:9c82:b0:6e1:2c94:1616 with SMTP id fj2-20020a1709069c8200b006e12c941616mr10274148ejc.64.1660564157061; Mon, 15 Aug 2022 04:49:17 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1660564157; cv=none; d=google.com; s=arc-20160816; b=UzXMTrrqqlGEDxx4wqLYc5n80dwGScN4gIFIhRrHs7Qb+g4kD9Y5hdzyzHgldiCK1X icR0CKxiK5j6PdjDyATW8SUIHePkP98v3jd7tVMAOEuuJZv8kgJqpUZm4sLTKjxA5R8m cIVIzbFp67zmZRB2nx9zm9yKg7CszSDEjiSkfVoFJ/kWWif3IoKjNTvVnMg869J7anrd 8TGS6j41ORJzTg2NbpzAFBOsGbjM6A/032dYob5Jh2Wv1j73mekBOv19NsBRwD4snVju 3Ui9aRMlGKbOMoXLJsr8kAMLAiSNuqgu3Bxco8ni8ZDKSIKXEKweoJQ7P7koKMzoiDrq 4A4w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:in-reply-to:from :content-language:references:cc:to:subject:user-agent:mime-version :date:message-id; bh=WcEE2xl+xxWHjE2rIpRVB8PuCdVI9kL9H2d71nbNA9s=; b=pnnqDMEDTS2oNqGQXTDjqQH6A2l2BCkBw9yDZH4qVzk5fsGRyob+B6kciWgccBK+R2 6vumSE6y7sauIM2hBra/mrwMSn2tc41KX+GYSuBcf6PTz4NAz7Yh0BJqSG7G9qQexrWH VAzhNeaCo8CzX3FK0o1/QiEpNTAHR/7F0qPQZAB1fTKBqRDm45tAcHAqbgzx1wgMIL8v nVL/GswJe/zVG/TIX4Gu8mXJlR9lWsrPPnCqv9g2fNKHK9BNUMyCPN8kPiADsYNEEgFG VoWYk/cBnZf1kBf78nB2MCvoq+TnVjcmwtkmloFiOIcwmrQAuRmNUX//ktugoMKhuo8J mkbA== ARC-Authentication-Results: i=1; mx.google.com; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id dz10-20020a0564021d4a00b0043be95ef714si8968736edb.437.2022.08.15.04.48.52; Mon, 15 Aug 2022 04:49:17 -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; 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=fail (p=QUARANTINE sp=QUARANTINE dis=NONE) header.from=huawei.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S241543AbiHOLGC (ORCPT + 99 others); Mon, 15 Aug 2022 07:06:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48386 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S242389AbiHOLFf (ORCPT ); Mon, 15 Aug 2022 07:05:35 -0400 Received: from szxga08-in.huawei.com (szxga08-in.huawei.com [45.249.212.255]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id E6BCE25EAD; Mon, 15 Aug 2022 04:04:59 -0700 (PDT) Received: from dggpemm500023.china.huawei.com (unknown [172.30.72.56]) by szxga08-in.huawei.com (SkyGuard) with ESMTP id 4M5rv70xxRz1M8wb; Mon, 15 Aug 2022 19:01:39 +0800 (CST) Received: from dggpemm500013.china.huawei.com (7.185.36.172) by dggpemm500023.china.huawei.com (7.185.36.83) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 15 Aug 2022 19:04:57 +0800 Received: from [127.0.0.1] (10.67.108.67) by dggpemm500013.china.huawei.com (7.185.36.172) with Microsoft SMTP Server (version=TLS1_2, cipher=TLS_ECDHE_RSA_WITH_AES_128_GCM_SHA256) id 15.1.2375.24; Mon, 15 Aug 2022 19:04:57 +0800 Message-ID: <1b8cfda9-8a33-91af-dee1-a0586a11adf1@huawei.com> Date: Mon, 15 Aug 2022 19:04:52 +0800 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:102.0) Gecko/20100101 Thunderbird/102.0 Subject: Re: [PATCH] x86/unwind/orc: Add 'unwind_debug' cmdline option To: , , CC: , , , , , , , , References: <20220815105808.17385-1-chenzhongjin@huawei.com> <20220815105808.17385-2-chenzhongjin@huawei.com> Content-Language: en-US From: Chen Zhongjin In-Reply-To: <20220815105808.17385-2-chenzhongjin@huawei.com> Content-Type: text/plain; charset="UTF-8"; format=flowed Content-Transfer-Encoding: 7bit X-Originating-IP: [10.67.108.67] X-ClientProxiedBy: dggems706-chm.china.huawei.com (10.3.19.183) To dggpemm500013.china.huawei.com (7.185.36.172) X-CFilter-Loop: Reflected X-Spam-Status: No, score=-4.2 required=5.0 tests=BAYES_00,NICE_REPLY_A, 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 I accidentally attached this with my patch. Please ignore this one. Thanks, Chen On 2022/8/15 18:58, Chen Zhongjin wrote: > 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 > --- > .../admin-guide/kernel-parameters.txt | 6 +++ > arch/x86/kernel/unwind_orc.c | 46 +++++++++++++++++++ > 2 files changed, 52 insertions(+) > > diff --git a/Documentation/admin-guide/kernel-parameters.txt b/Documentation/admin-guide/kernel-parameters.txt > index cc3ea8febc62..85d48f6052fd 100644 > --- a/Documentation/admin-guide/kernel-parameters.txt > +++ b/Documentation/admin-guide/kernel-parameters.txt > @@ -6317,6 +6317,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 38185aedf7d1..c539ca39e9f4 100644 > --- a/arch/x86/kernel/unwind_orc.c > +++ b/arch/x86/kernel/unwind_orc.c > @@ -13,8 +13,13 @@ > > #define orc_warn_current(args...) \ > ({ \ > + static bool dumped_before; > if (state->task == current && !state->error) \ > orc_warn(args); \ > + if (unwind_debug && !dumped_before) \ > + unwind_dump(state); \ > + dumped_before = true; \ > + } \ > }) > > extern int __start_orc_unwind_ip[]; > @@ -23,8 +28,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;