Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp661385pxa; Tue, 11 Aug 2020 11:47:07 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyuRv2wvpdGvbcq27jKPXk+9CMMpMFaS0OO//YewMy1oz9yjYVDtxNYTxQ701RY7tHFqy4U X-Received: by 2002:a17:906:140e:: with SMTP id p14mr28274358ejc.430.1597171627286; Tue, 11 Aug 2020 11:47:07 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597171627; cv=none; d=google.com; s=arc-20160816; b=Wsg6wxqvhe4n8VgJ/AehSFYjwAz18EuhFKzJlIFyxxD+3CAum1xChcSTnqxIw0xD6u MPq1ffP0JZmYew0AZw75oPSDwIr5NYDrCSiaN+8oeJZBfusCcUFWPO/vSbfHkPrQiqY5 vRTtVUSU4sTxpIDLRoiiH80nQq7gBAUVFwfEBOphu6bdp5BSbV1Kp+XwspXnCjI2sYjC 0ZqNYoatT90EJWd+9jOen4kNyjQUjMKvfLG76FnNN7fGuc6yHhQ5gbmsHzuvvgRPOqcI NDonxIh2gQs+6AzPaDRQGHlbhdKvChRxqYTLSWrixIUShkWxYvyWKvT4sNWk0AloNzN7 3oBQ== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:cc:to:subject:message-id:date:from :in-reply-to:references:mime-version:dkim-signature; bh=Rcqr7IEEdVp/PYIy+e4k4nefLJLdXAwPGWDE8E1RWjc=; b=sWLTO9HaK3YLorcA/YZ2VZL1J2iA20y9jesK1zMbYs1phJgrak1BVBf8fl4J7Duxpa RMNRI04NO7e2+YCzrV84lgupQWIOWbwQ79i+dO+knnF16UhpvdGu4UHrvsTVI44UF/k1 L08+O8G29GHjqcsU4REez/RRSZSekr2n1OKuq5EtbupY7XDmPL2idfItsTU8e5hZX7AA nX7QI2RCpjExA01XtrRO3zeQP6Xn5A6zzzl5LtM6TKa8E2K5dEXn7aXsw0fPg+JrK5PZ ecQUVDdsMbBi7lyYbXExX6OBZowbWJ60y6rNYmNG5LDF5Zhb6p31/Re+Y2S3xCEEcGS/ Z2RA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=N2D4pMFg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id a12si12884579ejv.186.2020.08.11.11.46.43; Tue, 11 Aug 2020 11:47:07 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=N2D4pMFg; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1726274AbgHKSqF (ORCPT + 99 others); Tue, 11 Aug 2020 14:46:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:33974 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1725886AbgHKSqF (ORCPT ); Tue, 11 Aug 2020 14:46:05 -0400 Received: from mail-wm1-x344.google.com (mail-wm1-x344.google.com [IPv6:2a00:1450:4864:20::344]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D2BFAC06174A for ; Tue, 11 Aug 2020 11:46:04 -0700 (PDT) Received: by mail-wm1-x344.google.com with SMTP id 9so3449450wmj.5 for ; Tue, 11 Aug 2020 11:46:04 -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=Rcqr7IEEdVp/PYIy+e4k4nefLJLdXAwPGWDE8E1RWjc=; b=N2D4pMFgjGn4hATidL2UNDrGnhvfU/Y6zwGhWJT6Zf6uYI/CFGj7yAbBip75px+tZ2 KkaQYHfPWXBJUU4yDGnGFtcIsyfz+NcUcyOmopTF1woRUFTR+Po3U93bhye+hXr6InbU dFBLQQsvYWzb5CkzGl/qmyq2biw3aDTyG50Qc= X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to:cc; bh=Rcqr7IEEdVp/PYIy+e4k4nefLJLdXAwPGWDE8E1RWjc=; b=DLV2qIbSJ8MKr750BghBu9obN4YwxlZvqcFzzuKPeX6aHWX/GwCCb4KAPmfbCoGMc1 QQH0MtxXGngbTglBAfCvMwvAmtrkfxoTD+a1psAQ0CUpIezLuNc6bR/6pBBFrVK0gavQ LKd4XbVH+09xNd2DQWlxttmRguZ15I7jwJgvloy3wpAvQ74mJw6ujVy7qsz1Zj03wH+1 3HhGki2I7XA79JMliop1Z7Zf/p4Hk8LRmgc4fZ4ppnULiEa3bNl6T+QjEnrtuMLi1Wxq mj+JgOHSsxmOiRQ3AVIe9XE+H+LA6VCTARrlaD3LQ7BldK4geYb3echmRWfOSrfAUQg7 v5fQ== X-Gm-Message-State: AOAM5314XDIQzPh30q5mHCZ7bpjGrP1bpdAsBeq5SLqtvtB/GOLvSyo6 Gdsbsi9Cn0L9YxQKlYhH9ZAbCQOJohvGuH+dKQaH X-Received: by 2002:a1c:ba42:: with SMTP id k63mr4982540wmf.31.1597171563533; Tue, 11 Aug 2020 11:46:03 -0700 (PDT) MIME-Version: 1.0 References: <20200811063659.284088-1-qiuwenbo@phytium.com.cn> In-Reply-To: From: Atish Patra Date: Tue, 11 Aug 2020 11:45:52 -0700 Message-ID: Subject: Re: [PATCH] riscv: Setup exception vector for K210 properly To: Anup Patel Cc: Qiu Wenbo , Damien Le Moal , Guo Ren , Vincent Chen , "linux-kernel@vger.kernel.org List" , Atish Patra , Albert Ou , Palmer Dabbelt , Zong Li , Paul Walmsley , Greentime Hu , linux-riscv Content-Type: text/plain; charset="UTF-8" Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Tue, Aug 11, 2020 at 1:41 AM Anup Patel wrote: > > On Tue, Aug 11, 2020 at 12:07 PM Qiu Wenbo wrote: > > > > Exception vector is missing on nommu platform and it is a big issue. > > This patch is tested in Sipeed MAIX Bit Dev Board. > > > > Fixes: 79b1feba5455 ("RISC-V: Setup exception vector early") > > Signed-off-by: Qiu Wenbo Thanks for testing it on the kendryte board. > > --- > > arch/riscv/kernel/smpboot.c | 1 + > > arch/riscv/kernel/traps.c | 11 ++++++++++- > > 2 files changed, 11 insertions(+), 1 deletion(-) > > > > diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c > > index 356825a57551..23cde0ceb39d 100644 > > --- a/arch/riscv/kernel/smpboot.c > > +++ b/arch/riscv/kernel/smpboot.c > > @@ -154,6 +154,7 @@ asmlinkage __visible void smp_callin(void) > > mmgrab(mm); > > current->active_mm = mm; > > > > + trap_init(); > > notify_cpu_starting(curr_cpuid); > > update_siblings_masks(curr_cpuid); > > set_cpu_online(curr_cpuid, 1); > > diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c > > index ad14f4466d92..a390239818ae 100644 > > --- a/arch/riscv/kernel/traps.c > > +++ b/arch/riscv/kernel/traps.c > > @@ -174,7 +174,16 @@ int is_valid_bugaddr(unsigned long pc) > > } > > #endif /* CONFIG_GENERIC_BUG */ > > > > -/* stvec & scratch is already set from head.S */ > > +/* stvec & scratch is already set from head.S when mmu is enabled */ > > void trap_init(void) > > { > > +#ifndef CONFIG_MMU > > + /* > > + * Set sup0 scratch register to 0, indicating to exception vector > > + * that we are presently executing in the kernel > > + */ > > + csr_write(CSR_SCRATCH, 0); > > + /* Set the exception vector address */ > > + csr_write(CSR_TVEC, &handle_exception); > > +#endif > > } > > -- > > 2.28.0 > > > > This issue seems to be only on the latest master branch of > Linux stable tree so this fix need not be a stable fix. > > For MMU kernel, the CSR_TVEC is setup in relocate() function > called from secondary_start_common() function of head.S > > For NoMMU kernel, we should set CSR_TVEC directly in > secondary_start_common() function as "#else" case of the > "#ifdef CONFIG_MMU". > That would enable the trap only for secondary harts. But the exception vector on boot hart is still uninitialized. How about this change ? diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S index d0c5c316e9bb..7822054dbd88 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -77,16 +77,6 @@ relocate: csrw CSR_SATP, a0 .align 2 1: - /* Set trap vector to exception handler */ - la a0, handle_exception - csrw CSR_TVEC, a0 - - /* - * Set sup0 scratch register to 0, indicating to exception vector that - * we are presently executing in kernel. - */ - csrw CSR_SCRATCH, zero - /* Reload the global pointer */ .option push .option norelax @@ -144,9 +134,23 @@ secondary_start_common: la a0, swapper_pg_dir call relocate #endif + call setup_trap_vector tail smp_callin #endif /* CONFIG_SMP */ +.align 2 +setup_trap_vector: + /* Set trap vector to exception handler */ + la a0, handle_exception + csrw CSR_TVEC, a0 + + /* + * Set sup0 scratch register to 0, indicating to exception vector that + * we are presently executing in kernel. + */ + csrw CSR_SCRATCH, zero + ret + .Lsecondary_park: /* We lack SMP support or have too many harts, so park this hart */ wfi @@ -240,6 +244,7 @@ clear_bss_done: call relocate #endif /* CONFIG_MMU */ + call setup_trap_vector /* Restore C environment */ la tp, init_task sw zero, TASK_TI_CPU(tp) > Regards, > Anup > > _______________________________________________ > linux-riscv mailing list > linux-riscv@lists.infradead.org > http://lists.infradead.org/mailman/listinfo/linux-riscv -- Regards, Atish