From patchwork Thu Feb 16 18:20:23 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Sunil V L X-Patchwork-Id: 58182 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:adf:eb09:0:0:0:0:0 with SMTP id s9csp456585wrn; Thu, 16 Feb 2023 10:22:37 -0800 (PST) X-Google-Smtp-Source: AK7set+DzLyqA3G2syus4IQW6jIGrZQ/V/OsEXTxl0kNaWlT9fQbpDKJwtxNkFDezourb0ZjHPKm X-Received: by 2002:a05:6a20:1443:b0:b9:7a47:bca5 with SMTP id a3-20020a056a20144300b000b97a47bca5mr7100574pzi.43.1676571757462; Thu, 16 Feb 2023 10:22:37 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1676571757; cv=none; d=google.com; s=arc-20160816; b=pFr2O3HaOVjSHmpo3pJmaclNCaVCiPjZspb43N+LdrW6HGZA3np9r27EAWvsBeoYxo dXgMXAwN/yMlK9pDr7iPXZ7gaheT1CK+eap0i/8t+XG8KCfgPdZkK5WIPA47zLmhwnA1 DZSJWrgtxKbY85q02d7ZXV4ar8GBIrt6blhyuYiu5d7XTn3YxS/sXBlppMIbBfRuoJF7 5+Z65krXrzsmpqOGTQq/X2qJlaTuOh77ejvmaciCQMCLS3jh1Y1EI6JQlUhBXMpYnKNF ezIeZyqxrAo6yYtot/XtrpA/FM0L3dj2pyJTxBRIkwjNvW5JuXGaCnh6nkMwhsAyFSlk hlhQ== 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=zt5AKTEcwHiFDwLgavojOfY1pFXS3U3JrowEB907ryU=; b=j1yBMBH9lgRStifZdGXQrpwOzp7VIco1fVL2omOjucmgFkCsE/7Xe+pXlnU0Q9ZBWC SxPSWef5jPuK90KCTpJQ/O85xXhw/033XaEBf6FtxNpOvGq/+YLewLYpX1iJE7c8WqUk 1W7Jmz4xdKacslbbIsML7be7fY3qQQtZpHksOllq4sRBUXLaTk/N4F7WOXZ6L3WaQ+Ek CCDvqCheLKCWiuHTwf6HJD6uYLoaMLhhfCFIf7YVhQpTmg4jR4nWuKdEwgCKgv1ODu7E mdaEP0s0WKaVEXyLMTC99vGsJN4Wisbt3iifxNi2yA8VpnSzIKocqCwoJI1baJALYME8 aFJA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=hh3s2Oim; 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 Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id g7-20020a056a000b8700b0058e1b16c4dcsi2617932pfj.142.2023.02.16.10.22.23; Thu, 16 Feb 2023 10:22:37 -0800 (PST) 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=@ventanamicro.com header.s=google header.b=hh3s2Oim; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S229448AbjBPSVE (ORCPT + 99 others); Thu, 16 Feb 2023 13:21:04 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:54706 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229454AbjBPSVB (ORCPT ); Thu, 16 Feb 2023 13:21:01 -0500 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 3442750ADF for ; Thu, 16 Feb 2023 10:20:57 -0800 (PST) Received: by mail-pj1-x102c.google.com with SMTP id z14-20020a17090abd8e00b00233bb9d6bdcso2955261pjr.4 for ; Thu, 16 Feb 2023 10:20:57 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date :message-id:reply-to; bh=zt5AKTEcwHiFDwLgavojOfY1pFXS3U3JrowEB907ryU=; b=hh3s2OimS73QDs15kWCc2k+lI5tdH7x4xpQgd7UXBzADhjqkPdoP9zDNLKlvXIcB3j WhapBBPx3FQ50Ef9UATRHacKSfPD51PY94qt/38FAuRex3S4rktbxTUVWewRc4eTYN40 JzddLtS9xtnca0cYhHjA8PPX+Fg2/plv2OigHAVwz7TcxcFWTyONo/Iy/ttkziIKqRJE 7gyNPrVRvfy1tgsW3pJO7dUBOd018tUx1cmCfyC7+4Q7P/xXrxcqGYWDpBJXntex4zNG tNdkvuY106SjtLM/sh3J66oTgx61nmV0t4JUqJc+AhDSIrDtCm3S9H4csLsaqCx/DFi6 CrtA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date:message-id:reply-to; bh=zt5AKTEcwHiFDwLgavojOfY1pFXS3U3JrowEB907ryU=; b=jHorHXagXsbX+xNMB/97OFoKMFo5cEyjoIM8DgEHVZalz3so0KgpbdIb7A1qc3IHw9 ujzqrjkNJgn8wvvDakbpVzoBNJxhzaZOJM5F1nLcEcdx5Tqks16600bN8Enc3NLyZT6u TpY2A9iBSqm2RSlW4Yt2/1HeCInqoaMsM67HT5cfpcat2iJS/62Mv6mHZ5AADu99MrYp mmlSjPKzDnv70xB8j3FS/sjz2bomq3hsxgBZVCQVIoqcDAN8CnZQnlwEX+u7gS6bItMQ 9zppTcOM/N3PJnJ+pypbgU5CQTDybtQ8PBZhSKqMxpECTlbco6C1BTM35t5BLMGlslvv p1rg== X-Gm-Message-State: AO0yUKU80+vZdCzE/llpuOzG6b2O2EsmOhSC6w3PwjVwDmFXvM3cxNxA Xr4eFs033vraV5Y3S4vgtkUlIw== X-Received: by 2002:a05:6a21:9814:b0:be:c217:9580 with SMTP id ue20-20020a056a21981400b000bec2179580mr5065551pzb.49.1676571656477; Thu, 16 Feb 2023 10:20:56 -0800 (PST) Received: from kerodi.Dlink ([49.206.14.226]) by smtp.gmail.com with ESMTPSA id n21-20020a637215000000b004dff15fc121sm1517574pgc.36.2023.02.16.10.20.52 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 16 Feb 2023 10:20:56 -0800 (PST) From: Sunil V L To: Palmer Dabbelt , Albert Ou , Paul Walmsley , "Rafael J . Wysocki" , Len Brown , Thomas Gleixner , Marc Zyngier , Jonathan Corbet Cc: linux-riscv@lists.infradead.org, linux-acpi@vger.kernel.org, linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, Conor Dooley , Andrew Jones , Anup Patel , Atish Patra , Jisheng Zhang , Anup Patel Subject: [PATCH V2 01/21] riscv: move sbi_init() earlier before jump_label_init() Date: Thu, 16 Feb 2023 23:50:23 +0530 Message-Id: <20230216182043.1946553-2-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230216182043.1946553-1-sunilvl@ventanamicro.com> References: <20230216182043.1946553-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_NONE, SPF_HELO_NONE,SPF_PASS autolearn=unavailable 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?1758012906898300351?= X-GMAIL-MSGID: =?utf-8?q?1758012906898300351?= From: Jisheng Zhang 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 86acd690d529..4335f08ffaf2 100644 --- a/arch/riscv/kernel/setup.c +++ b/arch/riscv/kernel/setup.c @@ -270,6 +270,7 @@ void __init setup_arch(char **cmdline_p) *cmdline_p = boot_command_line; early_ioremap_setup(); + sbi_init(); jump_label_init(); parse_early_param(); @@ -287,7 +288,6 @@ void __init setup_arch(char **cmdline_p) misc_mem_init(); init_resources(); - sbi_init(); #ifdef CONFIG_KASAN kasan_init();