Received: by 2002:a6b:500f:0:0:0:0:0 with SMTP id e15csp1856577iob; Thu, 19 May 2022 16:56:48 -0700 (PDT) X-Google-Smtp-Source: ABdhPJxIPMUgrUMc7/kqr2+SPybsF7rr2gddEhXKEqYqRBxsVIDmcGvgGLrBsSEO+erOiUHYm8qN X-Received: by 2002:a17:902:e053:b0:161:ba27:5216 with SMTP id x19-20020a170902e05300b00161ba275216mr7158837plx.79.1653004608479; Thu, 19 May 2022 16:56:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653004608; cv=none; d=google.com; s=arc-20160816; b=ipPaZ4xoaTiaU4X2pZvYdIqtVJErmaSzsnMtFGxUJfc2yXddFRbp5opl13eb046Gf6 X2z4ZKTY/njSZtqxMRMcwREbwGdmDVP4cRNyeUhYArG58lcMrBVb7qBBNmBZm6yxH9bY OYga48/LIbOicc79B95LXpYhCALUvKVFe+BOE3m4luSh60dOHjErzTsTvrqmAw6CTlus A9t6F5JH2Q8LImmSuQGAEwwnbCDY3yjQ7SGMOTYPvJpA46I41MYKNyhV+38NoIIswAL/ +uqq3cfhpyEjLWhSAwxFsuBC/KAZMdRP/fOgbZheNc45Okk7/9Ws9sJScVxzG36dkeQS ixJA== 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=/vLhOSCP5QNhrXNB+0eP1Vbw79xEqu/cnNqULBdNP0g=; b=IaBl006pnzadmWPeYQmhVpn8e6VNEhwyVZy/N3/UIA813Z1WezzkW/HHrIvtNNIoFI Rk++1AtlZyWlBy1bjUfZQmc1LtBnKNslSmaneDXPYOJxjz/cXeBC0xoRVdXLTgcS3iIm WmEpq2LvbsBHj+lr4rUU79AoUVsq+s9N+4vwV1figsM0oYWpu3pUsjKtBFJJ5Lx36ktR tGMmQ2VbqT7rpfQJWE5z+uMHv8EGvkymhMyrZ0yLb3w2fUakWbUrjP/g6TPD2xNLmOcn 4nwWg9TsXnWixrN3dzv6a7YOcCS7K+Riplp+/rNXuglH+Fo6tOBnZrCgwIQv+U0NSzW5 jhfg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=YonGe4NX; 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 ja21-20020a170902efd500b0016164e8816dsi7355500plb.247.2022.05.19.16.56.36; Thu, 19 May 2022 16:56:48 -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=YonGe4NX; 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 S233482AbiESQIT (ORCPT + 99 others); Thu, 19 May 2022 12:08:19 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54768 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S241776AbiESQIG (ORCPT ); Thu, 19 May 2022 12:08:06 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id B4574A0D04 for ; Thu, 19 May 2022 09:08:05 -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 71E2AB825B1 for ; Thu, 19 May 2022 16:08:04 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id D17CFC34113; Thu, 19 May 2022 16:07:56 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1652976483; bh=9UIogW/hGkD7UNMXBrouLXfFfzy7yMoOEYum4Eptm84=; h=From:To:Cc:Subject:Date:In-Reply-To:References:From; b=YonGe4NX2xCRT2Lj+eZF+8nXu3b0omXDd5Rk4kWFcd370QtqBpQEul36v+XG/OJJY 0hWhBZQ582oYmBZVLEYHvQJq/xe5QKPGQdxgRh32qFU2nYeAWkXkMNgQnF2fFxZbU3 ArQPkMe0LIeRkOm4/l2ejfKI2ZX+hp7kvbgBYI50TKtf5gy0Ufld0+mLzdV1s5xbjU OYXMoEcqQkS71MbeI8ziiAiLDD10ZDxvRodBOJAOeAvSfy6z+v2jJ8EZE0n0scSmJP nNbhmZEVQyAOch3t6VrUAsD1IOlsgcrQZ8ijWOg/mcseqSCee/0ChquCWWLRvYA5YI Wq1PwJr/6wDyw== From: Jisheng Zhang To: Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Alexandre Ghiti , Anup Patel , Atish Patra Cc: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, kasan-dev@googlegroups.com Subject: [PATCH v3 1/2] riscv: move sbi_init() earlier before jump_label_init() Date: Thu, 19 May 2022 23:59:17 +0800 Message-Id: <20220519155918.3882-2-jszhang@kernel.org> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20220519155918.3882-1-jszhang@kernel.org> References: <20220519155918.3882-1-jszhang@kernel.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-7.6 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 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 --- 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 834eb652a7b9..d150cedeb7e0 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -268,6 +268,7 @@ void __init setup_arch(char **cmdline_p) *cmdline_p = boot_command_line; early_ioremap_setup(); + sbi_init(); jump_label_init(); parse_early_param(); @@ -284,7 +285,6 @@ void __init setup_arch(char **cmdline_p) misc_mem_init(); init_resources(); - sbi_init(); #ifdef CONFIG_KASAN kasan_init(); -- 2.34.1