Received: by 2002:ac2:464d:0:0:0:0:0 with SMTP id s13csp3304855lfo; Mon, 23 May 2022 01:12:15 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyCxwS+o4hd6oPxzfWbmVK8ql3iUmPFjM0HHmR/AB8MTfy3NIbyH7JxBsEktdpp/488xbK4 X-Received: by 2002:a63:25c5:0:b0:3fa:387b:174f with SMTP id l188-20020a6325c5000000b003fa387b174fmr5053869pgl.161.1653293534899; Mon, 23 May 2022 01:12:14 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1653293534; cv=none; d=google.com; s=arc-20160816; b=IJjSPkpC1Ok530DGWr9+mbosTxgd0yAqMa36l7R2hZJozpzc8MUOHtJtbVJMmN1H9U 8h7dv5bnqOTd8CVv8qB+Ef8BpFMli+93T+ofui+HGpF9PKicx9uViySt3FgHgTF54ipQ KrxxgFmi7JYEcVgt1Rr/8y59wVjI/Zv9ZLwHi41CtRbBTnrufTibkDEqTnovjQ35Eiik b+ZMV0+tC5HP92zTtkipWRKMe/gDZEnSnTsZLVr1ymQNufabpAMPA0YBOCFg5H+JdlXe zxh88s1VOQxUtC6CyTCA/I9WNSo+6V8m3ixjpfT8emzWkn16zG+28IxTZvpaLcb79TVP 9Kxg== 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=iTR4F6Zdd5GmGSK+3VogNeE1cHs24uCXuHYRDacHFH0=; b=JrkYvr+Iu8YfhN46oVUUSYyE/r1syhDZ/mtKjLJKFTwd+4zkEKHOhLVjfXc06A67gF SN4cq/lYzb+epaeCqe6bmvAXoGpav0RYdklMFl6KuCrAW2+0LDcFaEPUfL8mJg6C4Jtr DLg5lQ+lPUpZ0kbd8mDZR2Ox8Zkg0L+IDy2yHNe3uNvUD+lQlTOynvCfcrlxe2jqcnxh vh1u7Pfpiac1nDM0+bb6sx7x0qajIf6yCNauB0RADyYwIMgJJHwItq8m+cZocbsm07+t iS4pABfCdPRX5MPTW0EzcM548go530GQL5IJXFOIIOUH+5jMx9192YoZFCNDccR8e9V3 3K3A== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=MBJcy6x7; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from lindbergh.monkeyblade.net (lindbergh.monkeyblade.net. [23.128.96.19]) by mx.google.com with ESMTPS id cu21-20020a17090afa9500b001d9e8ea9c13si11998405pjb.159.2022.05.23.01.12.14 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Mon, 23 May 2022 01:12:14 -0700 (PDT) Received-SPF: softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) client-ip=23.128.96.19; Authentication-Results: mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=MBJcy6x7; spf=softfail (google.com: domain of transitioning linux-kernel-owner@vger.kernel.org does not designate 23.128.96.19 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by lindbergh.monkeyblade.net (Postfix) with ESMTP id AE1C66B0BF; Mon, 23 May 2022 00:06:41 -0700 (PDT) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S239983AbiEVICH (ORCPT + 99 others); Sun, 22 May 2022 04:02:07 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:46032 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S240499AbiEVICD (ORCPT ); Sun, 22 May 2022 04:02:03 -0400 Received: from mail-yb1-xb32.google.com (mail-yb1-xb32.google.com [IPv6:2607:f8b0:4864:20::b32]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 05E622C109 for ; Sun, 22 May 2022 01:01:59 -0700 (PDT) Received: by mail-yb1-xb32.google.com with SMTP id p139so20495670ybc.11 for ; Sun, 22 May 2022 01:01:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=atishpatra.org; s=google; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=iTR4F6Zdd5GmGSK+3VogNeE1cHs24uCXuHYRDacHFH0=; b=MBJcy6x7M7Ay+fMd3UCpbOdofujh5V0wLWk1jvv1/hY7Oa7ImjQ8OgaAtQePnZ/aLq U/EAPeSLh3jD4fmffjn2cDZZXRrNIaLJk3YuZbQpPT/o9BzjUzvSc6MVy3ZSz/ZjOl1E pG2ZoltJ4iKhV+27FTcEy3PdUAAnSoPfHIWXw= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=iTR4F6Zdd5GmGSK+3VogNeE1cHs24uCXuHYRDacHFH0=; b=WumvOtXS20lejGx+ob/7i3zH0MaJms2R0+8FDqfJupcmm1lQnn4jMqbIqysgPL2WEN ajczJivqoQGWWyAMcomFYK8SQuXoyMh+unWsIq1bjHPlQl8udcLAi2XFe3VlkjBFJc/0 nQbe7i127MhD13NYRk2LMw+lGRmXv5nHp9sq97+AJWL+0IDyuijHgQH0E30cf9uHl9LG tDyRt+G9F/R/eGmOh6JldxSgMy/wdyG7B0fRRcjQSNj1DoTcbrgk9TrnVeN0jUsVitKp xW0jhUnj0xHDbiUBA4sw58hI7Ds4mTK7GwvxMTL3yvkaE7xKAwLCP/3309KK87TNTtuh 45Nw== X-Gm-Message-State: AOAM532VpniMWe/BwCW/+E2hfcWy7/3KQOXnLr45PvUSU2x56toFo/Qz ohQ+9uFFOBTEpp0dRWQI4DText5Y13IdgKtNqg/iISlKyQ== X-Received: by 2002:a25:941:0:b0:64d:da87:62ff with SMTP id u1-20020a250941000000b0064dda8762ffmr16707944ybm.459.1653206518170; Sun, 22 May 2022 01:01:58 -0700 (PDT) MIME-Version: 1.0 References: <20220521143456.2759-1-jszhang@kernel.org> <20220521143456.2759-2-jszhang@kernel.org> In-Reply-To: <20220521143456.2759-2-jszhang@kernel.org> From: Atish Patra Date: Sun, 22 May 2022 01:01:47 -0700 Message-ID: Subject: Re: [PATCH v4 1/2] riscv: move sbi_init() earlier before jump_label_init() To: Jisheng Zhang , Alexandre Ghiti Cc: Paul Walmsley , Palmer Dabbelt , Albert Ou , Andrey Ryabinin , Alexander Potapenko , Andrey Konovalov , Dmitry Vyukov , Vincenzo Frascino , Anup Patel , Atish Patra , linux-riscv , "linux-kernel@vger.kernel.org List" , kasan-dev@googlegroups.com Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-2.0 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,HEADER_FROM_DIFFERENT_DOMAINS, MAILING_LIST_MULTI,RDNS_NONE,SPF_HELO_NONE,T_SCC_BODY_TEXT_LINE autolearn=no 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 Sat, May 21, 2022 at 7:44 AM Jisheng Zhang wrote: > > 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() > @Alexandre Ghiti : Is this the root cause of the panic you were seeing ? IIRC, you mentioned in your last email that you don't see the issue anymore. May be you avoided the issue because alternatives usage was moved but root case remains as it is ? > 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 > > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv -- Regards, Atish