Received: by 2002:a05:6a10:a0d1:0:0:0:0 with SMTP id j17csp255432pxa; Wed, 12 Aug 2020 00:43:25 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyKSaihAf2vZqSxYEAjSaL0c8LJEADq8PmrdIqzDfmECIuIWdKZcvznqSqcok2P1rrq640E X-Received: by 2002:a17:907:aaa:: with SMTP id bz10mr29455567ejc.304.1597218205116; Wed, 12 Aug 2020 00:43:25 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1597218205; cv=none; d=google.com; s=arc-20160816; b=W3nTqGgH4cqyV4L6/k9p7yxlnyZyRxGsZaOTOJv2CAR0j+rFgJ7AkL2lk1A9JGpy0V +cEsCNUdMtk1UiRDXZoiOKevdK+blbzGlyRNxYxO5cmj9WGNBs9b7MxKMqJBo89x3nK6 bV0G/KdbapHP1cHkrkkeVqIFte7vkfOmlABPX1coVn3WkwXqnUuaLDvzuPGxhGqagl6R DQcLEiIhSA3OhQ3uMHnuinsDppteP2m0mAFQf0qVstkx3wYSNYIbTll7O2EbExSv/wPg 0dCqEP0iwFLlaTFRVAUnizrn48u3P/kx5fCCGQHpk1O/XRBk3uX55DGIfGYI8k8oL7n4 osuQ== 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=qcgI980fiRK7SzxZtdY0+aQKjgScVqiUUhN/ufIMkto=; b=UCVq6gTmmEzjSnYtlX4xvUAbzB+NhAWehePMQaUX3no1A+13+8KH04wS8hgyL2be/n d/SuYzJOAoIj7JBXpXpk1z1DJeRpEA5kjBsfOgja9eEB6iQd/P3hKTi7OVcq3aARcaci VeF1kvPgzmHC69Ed35IRuIyxj+dKPEAjcH+5WqjKkQQq1noldXA7IOeB6AVsjCfpwR6q Sxg8X1043EMfHKgCRO5r5jfo7XDF8yZa0r7JOni61OaiAr5fhtDm3+hDN+mog5MAsHtt DYxcvfWRdSGJID0GMbhcjpE78uCMLXu2gS029n7QR5I9rC8yiBa2YY7XkIzgVacZ/7qm QFZw== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@atishpatra.org header.s=google header.b=ie94EZvB; 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 x2si749256ejy.84.2020.08.12.00.43.02; Wed, 12 Aug 2020 00:43:25 -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=ie94EZvB; 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 S1726629AbgHLHlx (ORCPT + 99 others); Wed, 12 Aug 2020 03:41:53 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:40256 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726517AbgHLHlw (ORCPT ); Wed, 12 Aug 2020 03:41:52 -0400 Received: from mail-wr1-x442.google.com (mail-wr1-x442.google.com [IPv6:2a00:1450:4864:20::442]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4918BC06174A for ; Wed, 12 Aug 2020 00:41:52 -0700 (PDT) Received: by mail-wr1-x442.google.com with SMTP id p20so1105691wrf.0 for ; Wed, 12 Aug 2020 00:41:52 -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=qcgI980fiRK7SzxZtdY0+aQKjgScVqiUUhN/ufIMkto=; b=ie94EZvBjlMPBYC7v+ZULaM3vEkmlqRbQup1ISoqE7/k++/Nxg7Zo3hGSK6NGo6J2E ov5MLZQyA7Ey345t2WDXVw8/jykGfhDUCDePGYVmEm2Z6AitQLrEVkQXtv6LRmrT4rHF pSt/LUexc4sHFDschR7ooBgKqAcTMzk4XhZgY= 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=qcgI980fiRK7SzxZtdY0+aQKjgScVqiUUhN/ufIMkto=; b=X9RdbjKy6yoLYcMkQxXOY+P0WJ0p0q9CIFSUxRX+De0fzsjVTnzGEdtxxWiSR1e+jl ojgvEpZWDNCxYQFYYMAo1uwmFBvcszEzZZUZGuQPZbXAZ1jFGQhiuhx6Ej2YCEYG9d0/ Nucu0AG9LU/OwHJrziqnBB+a+M4EMN7wVeFBLOgAtcAZaTRPkgo+peqEE/KWA5rto/SO HaPegIPr6VhHCcpZ+s8aNE7PBmqwCCgJhEF3s5n5ONjLJMHG6x0T6xZ9BUGz6zFe8czp 1f8PMEsIPb/odBAtdEWTZEeCgNFVj4jNnLgh0YGYEs3iDiLIDxx/O2r/0u0HQbDyzlkX QP8w== X-Gm-Message-State: AOAM531USfeZdelPtM5tc6AndEXjbHTSS8wTkK9C0u0B67cl97xoqrj5 +H6Y2Hi0X9C7v0EOqQoJHrVsvnaMAAIM6jGTc2I5 X-Received: by 2002:adf:d84f:: with SMTP id k15mr31107746wrl.176.1597218110811; Wed, 12 Aug 2020 00:41:50 -0700 (PDT) MIME-Version: 1.0 References: <20200811063659.284088-1-qiuwenbo@phytium.com.cn> In-Reply-To: From: Atish Patra Date: Wed, 12 Aug 2020 00:41:39 -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 6:57 PM Anup Patel wrote: > > On Wed, Aug 12, 2020 at 12:16 AM Atish Patra wrote: > > > > 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 > > - > > Instead of having no trap vector setup here, we should > at least have dummy trap vector (just like original code). > Ahh yes. We should include that. > /* Set trap vector to spin forever to help debug */ > la a0, .Lsecondary_park > csrw CSR_TVEC, a0 > > > /* 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) > > Apart from above, this looks good. > > Regards, > Anup -- Regards, Atish