Received: by 2002:a6b:fb09:0:0:0:0:0 with SMTP id h9csp5623795iog; Thu, 23 Jun 2022 01:51:41 -0700 (PDT) X-Google-Smtp-Source: AGRyM1uXT39vL4hRlFVRGamdOnHv7+8b0PDwq04DxcXL+wOcAN6p4WIExXH14UkmQdiJRipyorsw X-Received: by 2002:a17:906:b150:b0:711:c6a5:c5c1 with SMTP id bt16-20020a170906b15000b00711c6a5c5c1mr7226196ejb.177.1655974301659; Thu, 23 Jun 2022 01:51:41 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1655974301; cv=none; d=google.com; s=arc-20160816; b=jCL1Hj6SDL9qEHXQD1aIiCTs3GMIXPC8fN6UKuHBB//VvtSpgoO1frt0qz28xyQtyN rj4CcPzSRXNb8OmyAF3VnjIsDkRjY2EkL2GLyzh92+nZhTlsvrtvUajuYaGQYVXHMnUj 5MGLA85+lmMqSOi++u9/LB5ADcVgtYFCRcGVMzgEmYmPfCVebIFOWdDtksgzEgz3fkaP iPtt/5qh/71zw9UaEsDGjPBg40o0Okt8jSX2JZajZffvtjEbiFPkkBw3AzR9o5bgkUPU efxdUE4PFpLWnPupsOi2sD33Gdhb1OVCyb/7VoN0Y3joTTF+fhL7GdqBpDU63540bmfP +yhQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=SvWRXBeeei4I3nJt5yps1vyjJBeYk64jRfo5c/RIgcA=; b=IWgBv2ue247tHJiufZRtv9+/VnqyhRhqBIkDk/9SpDeCPIDVi7FBrqx7VgtKRNmPgu kwDAmAnL8W91PUd5d/+00Ae9y185aPT/VOCZl1scOggktl1UT2HyIna6pBlyMSumj1Lf ttneps2iqJpaLC3Yrp36rVjFppelYNObvY6n1P3Hftfjus9ekaNed/T5QS3QlDF7+HgD J7HSP/IXGWhqqjpMVZpI4abYSO+LjU97golkMb6+eJcbc8tn9f6GngYixT6hqeLFiTu+ bPoTwYHKtDbVetLoEvgF4AL4WTo1m7/n/MOABXTM5EJbk0uuj6G+UP+eCKK7mzdZFpS3 XySg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=PITc58SL; 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=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id oz30-20020a1709077d9e00b007123ba1f12asi3092505ejc.552.2022.06.23.01.51.16; Thu, 23 Jun 2022 01:51:41 -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=@kernel.org header.s=k20201202 header.b=PITc58SL; 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=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230250AbiFWIbC (ORCPT + 99 others); Thu, 23 Jun 2022 04:31:02 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:43018 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229672AbiFWIbA (ORCPT ); Thu, 23 Jun 2022 04:31:00 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [IPv6:2604:1380:4601:e00::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 35AF248881 for ; Thu, 23 Jun 2022 01:30:59 -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 ams.source.kernel.org (Postfix) with ESMTPS id EE6D9B82208 for ; Thu, 23 Jun 2022 08:30:57 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id A3E10C341C8 for ; Thu, 23 Jun 2022 08:30:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1655973056; bh=F5UR30hB3x0X8hdoOCoBr2Sxf6O6bd2Ool5zcZGjk54=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=PITc58SLVQX6+OIXxpvKXrYmMz5ioJtqqdMDq/mVS+wq9Hzrq6vbceIYxwei51e1H 1bdhOQCXXfEuASliJ4yB4KQmj2/mwGVZgrlmWJS9w4oBz2cOVaMl5Fy6dxtZfsxqd4 YgzL1mzesjUDMGc9pcRSfQqqOsGl0I8FXMbaAn5S90V7AVFbOBOepEwh9dBSTnTgK9 7jjxoEXSmqmAu6AbEG3Ud8tj36I332As0K24M005Q2St/6chODoHoB1XuFZsAnfMEj GBM3z+2FX4WIFolnXQfxmjsbCoy8+efqx0WNgq1sMSPsJcOqoJUeP/F51YqlttrjKU 4r3NirXf2rqjw== Received: by mail-vs1-f51.google.com with SMTP id j1so9827513vsj.12 for ; Thu, 23 Jun 2022 01:30:56 -0700 (PDT) X-Gm-Message-State: AJIora8bq19+L9atwxnw8f4Uv9F6mkA7Ir/2aAX2+aYguqzEMOc0AUwX /jkODhNNTeVwQVdNadNVLKwpoGQodlNnJgge9o4= X-Received: by 2002:a05:6102:f8b:b0:354:57e8:4c1b with SMTP id e11-20020a0561020f8b00b0035457e84c1bmr4477837vsv.8.1655973055484; Thu, 23 Jun 2022 01:30:55 -0700 (PDT) MIME-Version: 1.0 References: <20220623074315.3814826-1-xianting.tian@linux.alibaba.com> In-Reply-To: <20220623074315.3814826-1-xianting.tian@linux.alibaba.com> From: Guo Ren Date: Thu, 23 Jun 2022 16:30:44 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH] RISC-V: use __smp_processor_id() instead of smp_processor_id() To: Xianting Tian Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Alex Ghiti , Liao Chang , Nick Kossifidis , linux-riscv , Linux Kernel Mailing List Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-7.7 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, 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 On Thu, Jun 23, 2022 at 3:43 PM Xianting Tian wrote: > > Use __smp_processor_id() to avoid check the preemption context when > CONFIG_DEBUG_PREEMPT enabled, as we will enter crash kernel and no > return. > > Without the patch, > [ 103.781044] sysrq: Trigger a crash > [ 103.784625] Kernel panic - not syncing: sysrq triggered crash > [ 103.837634] CPU1: off > [ 103.889668] CPU2: off > [ 103.933479] CPU3: off > [ 103.939424] Starting crashdump kernel... > [ 103.943442] BUG: using smp_processor_id() in preemptible [00000000] code: sh/346 > [ 103.950884] caller is debug_smp_processor_id+0x1c/0x26 > [ 103.956051] CPU: 0 PID: 346 Comm: sh Kdump: loaded Not tainted 5.10.113-00002-gce03f03bf4ec-dirty #149 > [ 103.965355] Call Trace: > [ 103.967805] [] walk_stackframe+0x0/0xa2 > [ 103.973206] [] show_stack+0x32/0x3e > [ 103.978258] [] dump_stack_lvl+0x72/0x8e > [ 103.983655] [] dump_stack+0x14/0x1c > [ 103.988705] [] check_preemption_disabled+0x9e/0xaa > [ 103.995057] [] debug_smp_processor_id+0x1c/0x26 > [ 104.001150] [] machine_kexec+0x22/0xd0 > [ 104.006463] [] __crash_kexec+0x6a/0xa4 > [ 104.011774] [] panic+0xfc/0x2b0 > [ 104.016480] [] sysrq_reset_seq_param_set+0x0/0x70 > [ 104.022745] [] __handle_sysrq+0x8c/0x154 > [ 104.028229] [] write_sysrq_trigger+0x5a/0x6a > [ 104.034061] [] proc_reg_write+0x58/0xd4 > [ 104.039459] [] vfs_write+0x7e/0x254 > [ 104.044509] [] ksys_write+0x58/0xbe > [ 104.049558] [] sys_write+0xe/0x16 > [ 104.054434] [] ret_from_syscall+0x0/0x2 > [ 104.067863] Will call new kernel at ecc00000 from hart id 0 > [ 104.074939] FDT image at fc5ee000 > [ 104.079523] Bye... > > With the patch we can got clear output, > [ 67.740553] sysrq: Trigger a crash > [ 67.744166] Kernel panic - not syncing: sysrq triggered crash > [ 67.809123] CPU1: off > [ 67.865210] CPU2: off > [ 67.909075] CPU3: off > [ 67.919123] Starting crashdump kernel... > [ 67.924900] Will call new kernel at ecc00000 from hart id 0 > [ 67.932045] FDT image at fc5ee000 > [ 67.935560] Bye... > > Fixes: 0e105f1d0037 ("riscv: use hart id instead of cpu id on machine_kexec") > Co-developed-by: Guo Ren - Co-developed-by: Guo Ren + Reviewed-by: Guo Ren Thx > Signed-off-by: Xianting Tian > --- > arch/riscv/kernel/machine_kexec.c | 2 +- > 1 file changed, 1 insertion(+), 1 deletion(-) > > diff --git a/arch/riscv/kernel/machine_kexec.c b/arch/riscv/kernel/machine_kexec.c > index df8e24559035..86d1b5f9dfb5 100644 > --- a/arch/riscv/kernel/machine_kexec.c > +++ b/arch/riscv/kernel/machine_kexec.c > @@ -171,7 +171,7 @@ machine_kexec(struct kimage *image) > struct kimage_arch *internal = &image->arch; > unsigned long jump_addr = (unsigned long) image->start; > unsigned long first_ind_entry = (unsigned long) &image->head; > - unsigned long this_cpu_id = smp_processor_id(); > + unsigned long this_cpu_id = __smp_processor_id(); > unsigned long this_hart_id = cpuid_to_hartid_map(this_cpu_id); > unsigned long fdt_addr = internal->fdt_addr; > void *control_code_buffer = page_address(image->control_code_page); > -- > 2.17.1 > -- Best Regards Guo Ren ML: https://lore.kernel.org/linux-csky/