Received: by 2002:a25:1506:0:0:0:0:0 with SMTP id 6csp5655105ybv; Tue, 11 Feb 2020 20:57:45 -0800 (PST) X-Google-Smtp-Source: APXvYqxo24KHwr42qUvrk3zjhz/wkace2cqvRfqWwLHR/UPLnV23YJxFe4jMG0Kp6DQa1RvuP6rl X-Received: by 2002:a9d:34c:: with SMTP id 70mr811033otv.174.1581483465820; Tue, 11 Feb 2020 20:57:45 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1581483465; cv=none; d=google.com; s=arc-20160816; b=fPGmGnMT7kNiDhqeaRIqLX6sGEoyZslT+DjdfQdiZ0As5/mVowAt/+r9cqI4NNm9F1 CNFOPyi7HyvPGQVY7JvgkmwipEcyV7RTJxloazLqYEyps4uoitQMfwXxsFYgAg+TpXkl PMtxJbrUV0ZCXc8oMnvxPn5prKTF5liZgPTe0uzCFmEqsd1UJXfb79KNf8zMPljN7Qnl XpVWaaoX7CDO1ZY0uF8iMj/ycViB64ZWxUFejHorXsDyRWuM5NkkIyQ13hpgdCNVb4ch vi/xm6j7R5AV08nP9jCOonQm1WTR+dHI5w016PGSs4g7W7B3+Oy0AXa0QCdkMI8N9pJX xu7Q== 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=6BmVz8M0DHmO6ndjWhbEydu5XNnhgxAMx801ictogH0=; b=OeFuNkUz+66ZNhiXre1cYxGCmPMcOHMo95L+Jl+68svZlcWtQO3PWPBHyiri22oq79 vvjctjWwz/aWsb00908gJyACD6lBNHPyzLxdMf82kcRZDIy5Itx+scosbqL6HXB3/qtb f3ENAuNsuFy1WTUtYIOt/PqH8I/SVfDkWi8cv+7uxMb3Het9etozW8zQWTc8kuZlvJzF umBEbC4pdNg1PmBaI5t4bh/a7mHFd+XClZYwMkh1cPN6ZW/sftON52fBBL6k9FjBUg+5 OgyOPcOheF7ZKNReSPlC6bi4pT7DQjmKfKT/woMW44gtb4D6l0t5sRqLEH/d87PSzGri IBSg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=g+YTRJuo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id c11si2726590oic.20.2020.02.11.20.57.32; Tue, 11 Feb 2020 20:57:45 -0800 (PST) Received-SPF: pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) client-ip=209.132.180.67; Authentication-Results: mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b=g+YTRJuo; spf=pass (google.com: best guess record for domain of linux-kernel-owner@vger.kernel.org designates 209.132.180.67 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1728032AbgBLE5X (ORCPT + 99 others); Tue, 11 Feb 2020 23:57:23 -0500 Received: from mail-wr1-f68.google.com ([209.85.221.68]:45264 "EHLO mail-wr1-f68.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727904AbgBLE5X (ORCPT ); Tue, 11 Feb 2020 23:57:23 -0500 Received: by mail-wr1-f68.google.com with SMTP id g3so514884wrs.12 for ; Tue, 11 Feb 2020 20:57:20 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=brainfault-org.20150623.gappssmtp.com; s=20150623; h=mime-version:references:in-reply-to:from:date:message-id:subject:to :cc; bh=6BmVz8M0DHmO6ndjWhbEydu5XNnhgxAMx801ictogH0=; b=g+YTRJuo4tDXTnbiJgTSMYfeGIYy0IZgZjoegtGBMTBYJ4RqZJKGPGRD0Hbshg0GTD n7I8FpIAqlet+MD0Eg7vZESGIPtvUKp0OdawI5mZrRLsDoFFSSOYbh43owWApRSv9gpd TEeOHmrM0K40AFVUOMSootpcheA7qapdssRmyEKAsv+nad4+fDeGeC+sMYLO9apAhRmI RWU0fUYQyYvfI0KwV1FqfXXNNLIM3c92O/iV8Q8JwNB4M0YWrB8pzrPJHS47bNmq89nj FrS40WdVYxWQdqPrjIsa8xTUkpNvDp+9yfx3DdeHplCgbbpks87nXggmdNo6uKv0eNhA XOHg== 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=6BmVz8M0DHmO6ndjWhbEydu5XNnhgxAMx801ictogH0=; b=a3rIj8w3NIazZTpQuRrtwcVbKl4rRj3krxYNmn4YQsyJlsJgjmTDC27VQH+7PtuxYc GWMJ8V1Hv4OlgWRMtdIIU5PMLYYATOKzJYWnhXvrBKmY/IpkZFltQXGSHzRY5j+2J/ho u6KwsI0D2umMVvqMJDLV2jXzWRwa16mn3fE6v6iJvaJZ8rLbPPEpCmFClUknH64K+N1m T7K3XxWGWjzM3B28HKbRDimCvCG6Gou4828C25a4RSsbumKRlbVZp7DfXmWjsJIVDMv5 iiWirbmhcPBHEs1ZssRDOPhpe9ECa8PgSTqIdizj5aqKIWkaA+ZsLTmhGw36rTRtw30l 5xvw== X-Gm-Message-State: APjAAAXckX6smVq54uOyZUHc4MO3cEOQ/wRZmFfL/qHYQBtVkxSRoCQ0 7G+b6oFUY7KDMdPvKkwC9f9hJZ8DazMZ0Pn8hh9DdrzpyoE= X-Received: by 2002:adf:f28f:: with SMTP id k15mr12564779wro.230.1581483439490; Tue, 11 Feb 2020 20:57:19 -0800 (PST) MIME-Version: 1.0 References: <20200212014822.28684-1-atish.patra@wdc.com> <20200212014822.28684-10-atish.patra@wdc.com> In-Reply-To: <20200212014822.28684-10-atish.patra@wdc.com> From: Anup Patel Date: Wed, 12 Feb 2020 10:27:08 +0530 Message-ID: Subject: Re: [PATCH v8 09/11] RISC-V: Add supported for ordered booting method using HSM To: Atish Patra Cc: "linux-kernel@vger.kernel.org List" , Albert Ou , Allison Randal , Borislav Petkov , Daniel Lezcano , "Eric W. Biederman" , Geert Uytterhoeven , Heiko Carstens , Jason Cooper , Kees Cook , linux-riscv , Mao Han , Marc Zyngier , Marek Szyprowski , Michael Ellerman , Mike Rapoport , Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Vincent Chen 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 Wed, Feb 12, 2020 at 7:21 AM Atish Patra wrote: > > Currently, all harts have to jump Linux in RISC-V. This complicates the > multi-stage boot process as every transient stage also has to ensure all > harts enter to that stage and jump to Linux afterwards. It also obstructs > a clean Kexec implementation. > > SBI HSM extension provides alternate solutions where only a single hart > need to boot and enter Linux. The booting hart can bring up secondary > harts one by one afterwards. > > Add SBI HSM based cpu_ops that implements an ordered booting method in > RISC-V. This change is also backward compatible with older firmware not > implementing HSM extension. If a latest kernel is used with older > firmware, it will continue to use the default spinning booting method. > > Signed-off-by: Atish Patra > --- > arch/riscv/kernel/cpu_ops.c | 10 +++++++++- > arch/riscv/kernel/cpu_ops_sbi.c | 31 +++++++++++++++++++++++++++++++ > arch/riscv/kernel/head.S | 26 ++++++++++++++++++++++++++ > arch/riscv/kernel/smpboot.c | 2 +- > arch/riscv/kernel/traps.c | 2 +- > 5 files changed, 68 insertions(+), 3 deletions(-) > > diff --git a/arch/riscv/kernel/cpu_ops.c b/arch/riscv/kernel/cpu_ops.c > index 1085def3735a..6221bbedaea4 100644 > --- a/arch/riscv/kernel/cpu_ops.c > +++ b/arch/riscv/kernel/cpu_ops.c > @@ -18,6 +18,7 @@ const struct cpu_operations *cpu_ops[NR_CPUS] __ro_after_init; > void *__cpu_up_stack_pointer[NR_CPUS]; > void *__cpu_up_task_pointer[NR_CPUS]; > > +extern const struct cpu_operations cpu_ops_sbi; > extern const struct cpu_operations cpu_ops_spinwait; > > void cpu_update_secondary_bootdata(unsigned int cpuid, > @@ -34,7 +35,14 @@ void cpu_update_secondary_bootdata(unsigned int cpuid, > > int __init cpu_set_ops(int cpuid) > { > - cpu_ops[cpuid] = &cpu_ops_spinwait; > +#if IS_ENABLED(CONFIG_RISCV_SBI) > + if (sbi_probe_extension(SBI_EXT_HSM) > 0) { > + if (!cpuid) > + pr_info("SBI v0.2 HSM extension detected\n"); > + cpu_ops[cpuid] = &cpu_ops_sbi; > + } else > +#endif > + cpu_ops[cpuid] = &cpu_ops_spinwait; > > return 0; > } > diff --git a/arch/riscv/kernel/cpu_ops_sbi.c b/arch/riscv/kernel/cpu_ops_sbi.c > index 9bdb60e0a4df..31487a80c3b8 100644 > --- a/arch/riscv/kernel/cpu_ops_sbi.c > +++ b/arch/riscv/kernel/cpu_ops_sbi.c > @@ -7,9 +7,13 @@ > > #include > #include > +#include > #include > #include > > +extern char secondary_start_sbi[]; > +const struct cpu_operations cpu_ops_sbi; > + > static int sbi_hsm_hart_stop(void) > { > struct sbiret ret; > @@ -46,3 +50,30 @@ static int sbi_hsm_hart_get_status(unsigned long hartid) > else > return ret.value; > } > + > +static int sbi_cpu_start(unsigned int cpuid, struct task_struct *tidle) > +{ > + int rc; > + unsigned long boot_addr = __pa_symbol(secondary_start_sbi); > + int hartid = cpuid_to_hartid_map(cpuid); > + > + cpu_update_secondary_bootdata(cpuid, tidle); > + rc = sbi_hsm_hart_start(hartid, boot_addr, 0); > + > + return rc; > +} > + > +static int sbi_cpu_prepare(unsigned int cpuid) > +{ > + if (!cpu_ops_sbi.cpu_start) { > + pr_err("cpu start method not defined for CPU [%d]\n", cpuid); > + return -ENODEV; > + } > + return 0; > +} > + > +const struct cpu_operations cpu_ops_sbi = { > + .name = "sbi", > + .cpu_prepare = sbi_cpu_prepare, > + .cpu_start = sbi_cpu_start, > +}; > diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S > index c1be597d22a1..8386cfafba98 100644 > --- a/arch/riscv/kernel/head.S > +++ b/arch/riscv/kernel/head.S > @@ -99,11 +99,37 @@ relocate: > ret > #endif /* CONFIG_MMU */ > #ifdef CONFIG_SMP > + .global secondary_start_sbi > +secondary_start_sbi: > + /* Mask all interrupts */ > + csrw CSR_IE, zero > + csrw CSR_IP, zero > + > + /* Load the global pointer */ > + .option push > + .option norelax > + la gp, __global_pointer$ > + .option pop > + > + /* > + * Disable FPU to detect illegal usage of > + * floating point in kernel space > + */ > + li t0, SR_FS > + csrc CSR_STATUS, t0 > + > /* Set trap vector to spin forever to help debug */ > la a3, .Lsecondary_park > csrw CSR_TVEC, a3 > > slli a3, a0, LGREG > + la a4, __cpu_up_stack_pointer > + la a5, __cpu_up_task_pointer > + add a4, a3, a4 > + add a5, a3, a5 > + REG_L sp, (a4) > + REG_L tp, (a5) > + > .global secondary_start_common > secondary_start_common: > > diff --git a/arch/riscv/kernel/smpboot.c b/arch/riscv/kernel/smpboot.c > index 2ee41c779a16..2c56ac70e64d 100644 > --- a/arch/riscv/kernel/smpboot.c > +++ b/arch/riscv/kernel/smpboot.c > @@ -146,7 +146,7 @@ void __init smp_cpus_done(unsigned int max_cpus) > /* > * C entry point for a secondary processor. > */ > -asmlinkage __visible void __init smp_callin(void) > +asmlinkage __visible void smp_callin(void) > { > struct mm_struct *mm = &init_mm; > > diff --git a/arch/riscv/kernel/traps.c b/arch/riscv/kernel/traps.c > index f4cad5163bf2..0063dd7318d6 100644 > --- a/arch/riscv/kernel/traps.c > +++ b/arch/riscv/kernel/traps.c > @@ -147,7 +147,7 @@ int is_valid_bugaddr(unsigned long pc) > } > #endif /* CONFIG_GENERIC_BUG */ > > -void __init trap_init(void) > +void trap_init(void) > { > /* > * Set sup0 scratch register to 0, indicating to exception vector > -- > 2.24.0 > Overall, this patch looks good but SBI HSM helper functions from PATCH8 should be moved to this patch. Reviewed-by: Anup Patel Regards, Anup