From patchwork Tue Apr 4 18:20:15 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: 79329 Return-Path: Delivered-To: ouuuleilei@gmail.com Received: by 2002:a59:b0ea:0:b0:3b6:4342:cba0 with SMTP id b10csp77947vqo; Tue, 4 Apr 2023 11:24:17 -0700 (PDT) X-Google-Smtp-Source: AKy350YWLAr5BeDr40GYlnoSwk4eUF6IxkUmSm4y9omQx+VY1EtXymVGbgVlzIQxOqbm8TJ10g7G X-Received: by 2002:a17:90b:1d0b:b0:23f:582d:f45f with SMTP id on11-20020a17090b1d0b00b0023f582df45fmr3976236pjb.1.1680632656819; Tue, 04 Apr 2023 11:24:16 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1680632656; cv=none; d=google.com; s=arc-20160816; b=AgkvtvxtzmztpT0eHQnQ7e1QDkjINB3CwSjZlpgvHBD5zqU8fWyFglXb0yWeReK+mp IbhcbQSlropX2mbInNjV8mZ2UOXpnoZwjASFZgDatnHvX2hPFEfQLNHqt6/32J9ZA+hu VYH3rbU4oML7OLduFnLNSuGmUNO3zuSnMVh5VSu5e2P915Zp/g9B70h9+4bNflnW38dR vsP6pXMaghKjas/C5CdJNuqdI7wSbD2RK1fe6H6DUyy0MLQO7z2o656NWVbdJaUfNUEr vcdZ+GiTLvWvD4y0/SSZIAJf23jzfgHzBGYOAIy2tXOXVa4t0nmHVxT6axUF1ClRtYAu d54A== 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=sFClBCEHVbePO27Fju+ZNSU82apTBuXNOZbPa4NKUXM=; b=nIyKYkfg3lF9WcTy4vnSl5QNny3pR/KVsu3TqBsYtLex0AmR8C9+xEBaq6tbycnmUw Tht6y0iECLAY4moGsUSlQxuL35mTmHOxwmze4w3kyyCTJ/f8EpId+zywcHJC3sz1m6JR 2RXMFvvc8yQBXvuaTW4u67EyOCgGXx+R+NrpfngJjq4xubZUy24WnsMhaHKIZ3+XkDFI cdZ0tENdNXky/eP15nMNNPn4oK5Cs1Ti5mSLZ4DbGkfB+4+OZ1nh0LBIRPdAi2/ewP2y yUXhttrTT7KnwTsZTupuHW5mpuZ+tzWB45swyJSBy0ewmtEH3h5uv9Y9K8tp2kCHpRsZ tTbw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@ventanamicro.com header.s=google header.b=om+MvbIf; 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 w62-20020a638241000000b0050308cba870si10994477pgd.137.2023.04.04.11.24.03; Tue, 04 Apr 2023 11:24:16 -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=@ventanamicro.com header.s=google header.b=om+MvbIf; 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 S236260AbjDDSVB (ORCPT + 99 others); Tue, 4 Apr 2023 14:21:01 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:37526 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S236081AbjDDSU4 (ORCPT ); Tue, 4 Apr 2023 14:20:56 -0400 Received: from mail-pj1-x1030.google.com (mail-pj1-x1030.google.com [IPv6:2607:f8b0:4864:20::1030]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 36EE449FE for ; Tue, 4 Apr 2023 11:20:55 -0700 (PDT) Received: by mail-pj1-x1030.google.com with SMTP id j13so31488382pjd.1 for ; Tue, 04 Apr 2023 11:20:55 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=ventanamicro.com; s=google; t=1680632454; 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=sFClBCEHVbePO27Fju+ZNSU82apTBuXNOZbPa4NKUXM=; b=om+MvbIfkns+lZbqNbgcHMnMZ2aS9j/NYOq4lBfq9dvmvbIbK+bYbVagLcbJpgUZO8 mmRoZClKwquID3cdxGwLpHtlme2c33/QGg0ULgIyNwAWM9lfbQripd+BYUbtMGoMALqq yslkspYHp6saGqpBe4+zRbCTVDgoT0uachN+dQ/4nvwB0FrDMieV9yJ3JIoWMN5/UX4f mr16wMm7Z0ZiIms+Bpc6PiKx3S7pGKG5IhM/mqGccAH3jII5CbdECQYlsXOsS0riBwgN oCVfMv7bgv2iAJc0k2oumrPXADtSumTnjjQv7K6owS7V4PoMmfKp0jS+qC3qY51c66xv LN8A== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; t=1680632454; 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=sFClBCEHVbePO27Fju+ZNSU82apTBuXNOZbPa4NKUXM=; b=wnBqdmauQEfxazUXXbfL5fSSGEIiJS2ohrly0oATS8mLhSWqIhj+BsNWEF6GYFMzzh +/g9U7WNVXzT/vqtpO7OJ/tNIeFm/69KILXAMW9cPBI4knQO5Ie363H3Ub5p28gAdj39 s6F/HrZchQVZxl2uRZfxqQNdK8V3G/Ntq5pAZLNRlbv7WPQEregAeMh066AgyJPHZgk9 +uD1HIEotFzZc5G8UMhiVIOQmHDCTbDrEa4qJdBbYqHlTtwEP+uo+cbe4ftYxWYQrjuv tLozWgbVF65m8F7yL5iAD3hHVwVUoVL2hcenJt5lFKhWWeMdI0hEQRHcOJbcTy5v3b6k TxpQ== X-Gm-Message-State: AAQBX9dFqq1JIldy9fuC+EF3nTfU/l1oAI9n2EbRpae3/TEpm/bb6yal pZzzX4ON5TGI85xGf9q7M48KcA== X-Received: by 2002:a05:6a20:9321:b0:c7:5cb6:2ff7 with SMTP id r33-20020a056a20932100b000c75cb62ff7mr2950473pzh.22.1680632454649; Tue, 04 Apr 2023 11:20:54 -0700 (PDT) Received: from localhost.localdomain ([106.51.184.50]) by smtp.gmail.com with ESMTPSA id o12-20020a056a001bcc00b0062dcf5c01f9sm9018524pfw.36.2023.04.04.11.20.47 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 04 Apr 2023 11:20:54 -0700 (PDT) From: Sunil V L To: linux-doc@vger.kernel.org, linux-kernel@vger.kernel.org, linux-riscv@lists.infradead.org, linux-acpi@vger.kernel.org, linux-crypto@vger.kernel.org, platform-driver-x86@vger.kernel.org, llvm@lists.linux.dev Cc: Jonathan Corbet , Paul Walmsley , Palmer Dabbelt , Albert Ou , Len Brown , Daniel Lezcano , Thomas Gleixner , Weili Qian , Zhou Wang , Herbert Xu , Marc Zyngier , Maximilian Luz , Hans de Goede , Mark Gross , Nathan Chancellor , Nick Desaulniers , Tom Rix , "Rafael J . Wysocki" , "David S . Miller" , Jisheng Zhang , Anup Patel , Atish Patra Subject: [PATCH V4 01/23] riscv: move sbi_init() earlier before jump_label_init() Date: Tue, 4 Apr 2023 23:50:15 +0530 Message-Id: <20230404182037.863533-2-sunilvl@ventanamicro.com> X-Mailer: git-send-email 2.34.1 In-Reply-To: <20230404182037.863533-1-sunilvl@ventanamicro.com> References: <20230404182037.863533-1-sunilvl@ventanamicro.com> MIME-Version: 1.0 X-Spam-Status: No, score=-0.2 required=5.0 tests=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?1762271068416244508?= X-GMAIL-MSGID: =?utf-8?q?1762271068416244508?= 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 376d2827e736..2d45a416d283 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();