Received: by 2002:ad5:4acb:0:0:0:0:0 with SMTP id n11csp1360649imw; Sat, 16 Jul 2022 05:04:59 -0700 (PDT) X-Google-Smtp-Source: AGRyM1tGjBQKJDnm6rCSeqLBOSrKUdcvz8H8fm54wjZVV7byzJnuUMAtxwY6M6nFhALqxuIHMdtd X-Received: by 2002:a65:604a:0:b0:401:9c5f:876b with SMTP id a10-20020a65604a000000b004019c5f876bmr16591394pgp.459.1657973099687; Sat, 16 Jul 2022 05:04:59 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1657973099; cv=none; d=google.com; s=arc-20160816; b=p2nbxTKOYcgbfhiJdr2dgcKXbPQtxsRjTDB5t5lFEziknQDoOQfIGWp0u9fHpqE4vu 37pz6XHiEO2xB2QDk7nBAaMpDgzUwzP6Ouh1VE8KA5FO3mCkUSKqnReq9wo2zR/mY8cD jtWp4zppQ5gf0bMuDmpvRq0KaPe6c7Wu+rHVU4YBYkUL4t6rbnK7/aW2s6U6nMgWNM4+ 28ri5tvz8g7szeNJnCBZIKOdhquEj+/b9CdVhtacbYFa9EyG73s2Ep59IGeJjkGQCS/9 vIzlTgajahogYPSstM7WLa2q7eVfpJJPubMFqMURSblJjwBDwRycIRR2NBuIbh3AjRhT lprQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :dkim-signature; bh=eMXBf7KhZsXe8C6gWPYl/qlwrLsAnBlpMpGYf9/z1fA=; b=aocOWphurk6OkjhVSyfJydSkvLX5ND3ckCLz/BOf+PM+r3LYqjvWzUH6kb5A4cXHbm 7bhy38LH1cP24w7lbRcTjmGuFiBM+FSWxODJFV88aJFEmv5A/1IK6JpOsEPR6aELjZ0w RQZ1LKyuVdK2c1JMknOGJaof0gtN8RS/NzmBN/8kNzXBUAX2T5Melu3wz6KE1DtZzpS4 icQqGBRo9vbj7jfy08w8dtnM8ks+nt4PHe2PU1XzhdgKMRDVsw/oPSJ8QSBVBUQcBIFQ 3H/+ZDRC0yQLDuAFjghX2tthfw4gF2FVkF5VzWEC4fK2pl1nTMxaxER0Os31Gp14Terb Kzmw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=ZDDi5kb7; 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 x11-20020a17090a8a8b00b001ef9079bcb4si7960539pjn.22.2022.07.16.05.04.44; Sat, 16 Jul 2022 05:04:59 -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=ZDDi5kb7; 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 S231238AbiGPMAH (ORCPT + 99 others); Sat, 16 Jul 2022 08:00:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:47666 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S231192AbiGPMAE (ORCPT ); Sat, 16 Jul 2022 08:00:04 -0400 Received: from dfw.source.kernel.org (dfw.source.kernel.org [IPv6:2604:1380:4641:c500::1]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3BE3924088 for ; Sat, 16 Jul 2022 05:00:03 -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 B8C2960B25 for ; Sat, 16 Jul 2022 12:00:02 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 02EBCC34115; Sat, 16 Jul 2022 11:59:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1657972802; bh=YUhixDNi1KCSLXxkbbdwq4C/qBo/zV52buAYC20HAIA=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=ZDDi5kb7n+T0GrIaSJbujYSplT2v5vZatC9rqWzMmJfIjEsV3WW5eBSE3R13Xoq3V Wf//r8gpGNcdeFsLobewz2ozV9s8fObyPqYb1CmdZSGnnpHpVEjGiwq722QUem1z+N AaxgSo8U76duzhTUm4SjH+UMr8LdjN7mGcSKmLb00ZdXf6cYnC5WDYpRLReURCOred waxRhBADTW5uo1agC88nn+EdebcySRmpr7WZhLbtU3oEIUzwJDSX+QgTEG8029T8Uq X/+emtAYGbw3Ll2hW2C0i2rVvkypzUTF1s7f0vjrkTm1LU9K3lTo6LwbR7eyhbxrwi R0TIqx5IYjslw== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Alexandre Ghiti , Emil Renner Berthing Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com, Anup Patel , Atish Patra Subject: [PATCH v6 1/2] riscv: move sbi_init() earlier before jump_label_init() Date: Sat, 16 Jul 2022 19:50:58 +0800 Message-Id: <20220716115059.3509-2-jszhang@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220716115059.3509-1-jszhang@kernel.org> References: <20220716115059.3509-1-jszhang@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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 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 We call jump_label_init() in setup_arch() is to use static key mechanism earlier, but riscv jump label relies on the sbi functions, If we enable static key before sbi_init(), the code path looks like: static_branch_enable() .. arch_jump_label_transform() patch_text_nosync() flush_icache_range() flush_icache_all() sbi_remote_fence_i() for CONFIG_RISCV_SBI case __sbi_rfence() Since sbi isn't initialized, so NULL deference! Here is a typical panic log: [ 0.000000] Unable to handle kernel NULL pointer dereference at virtual address 0000000000000000 [ 0.000000] Oops [#1] [ 0.000000] Modules linked in: [ 0.000000] CPU: 0 PID: 0 Comm: swapper Not tainted 5.18.0-rc7+ #79 [ 0.000000] Hardware name: riscv-virtio,qemu (DT) [ 0.000000] epc : 0x0 [ 0.000000] ra : sbi_remote_fence_i+0x1e/0x26 [ 0.000000] epc : 0000000000000000 ra : ffffffff80005826 sp : ffffffff80c03d50 [ 0.000000] gp : ffffffff80ca6178 tp : ffffffff80c0ad80 t0 : 6200000000000000 [ 0.000000] t1 : 0000000000000000 t2 : 62203a6b746e6972 s0 : ffffffff80c03d60 [ 0.000000] s1 : ffffffff80001af6 a0 : 0000000000000000 a1 : 0000000000000000 [ 0.000000] a2 : 0000000000000000 a3 : 0000000000000000 a4 : 0000000000000000 [ 0.000000] a5 : 0000000000000000 a6 : 0000000000000000 a7 : 0000000000080200 [ 0.000000] s2 : ffffffff808b3e48 s3 : ffffffff808bf698 s4 : ffffffff80cb2818 [ 0.000000] s5 : 0000000000000001 s6 : ffffffff80c9c345 s7 : ffffffff80895aa0 [ 0.000000] s8 : 0000000000000001 s9 : 000000000000007f s10: 0000000000000000 [ 0.000000] s11: 0000000000000000 t3 : ffffffff80824d08 t4 : 0000000000000022 [ 0.000000] t5 : 000000000000003d t6 : 0000000000000000 [ 0.000000] status: 0000000000000100 badaddr: 0000000000000000 cause: 000000000000000c [ 0.000000] ---[ end trace 0000000000000000 ]--- [ 0.000000] Kernel panic - not syncing: Attempted to kill the idle task! [ 0.000000] ---[ end Kernel panic - not syncing: Attempted to kill the idle task! ]--- Fix this issue by moving sbi_init() earlier before jump_label_init() Signed-off-by: Jisheng Zhang Reviewed-by: Anup Patel Reviewed-by: Atish Patra --- arch/riscv/kernel/setup.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/arch/riscv/kernel/setup.c b/arch/riscv/kernel/setup.c index f0f36a4a0e9b..f5762f7b982d 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -269,6 +269,7 @@ void __init setup_arch(char **cmdline_p) *cmdline_p = boot_command_line; early_ioremap_setup(); + sbi_init(); jump_label_init(); parse_early_param(); @@ -285,7 +286,6 @@ void __init setup_arch(char **cmdline_p) misc_mem_init(); init_resources(); - sbi_init(); #ifdef CONFIG_KASAN kasan_init(); -- 2.34.1