Received: by 2002:a25:e7d8:0:0:0:0:0 with SMTP id e207csp65236ybh; Tue, 17 Mar 2020 18:13:48 -0700 (PDT) X-Google-Smtp-Source: ADFU+vthjf+DnPCMZhhEzo4uDvOOOsI6C7qu3d1R+aqePshEdCQw/G3p9S5LIVSkc011uIRKNhlI X-Received: by 2002:a9d:6142:: with SMTP id c2mr1932309otk.92.1584494028796; Tue, 17 Mar 2020 18:13:48 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1584494028; cv=none; d=google.com; s=arc-20160816; b=v0RuCdFmb4ypbliRBOWXT6514RLNjKGrG/3h3FcuZXLL7rd4C+0uSpFbXeuJUVAWdh oawbwX7wOdYZsCNqzT98sRNSZkXsfzDYhGT51Vyp7v7P0D3PEBtTD+hHK6TzxsW3FBnp /WbiZWzFddsHpHl32o3+8IGJ06ZcrWuEGXA1MsG3lG/uZvXusUW4Un4smkfk2NJu4R3N MTNSux+XK5fGs0qGPAGqStYpOWfdviOUxa+G6giRA/YEmi+EL1SP9QEOrOVbQuLVjt/i cJgMrl5MrUe36R9mT+R4WEHI9BhThQOdl5AWWeu/JQur8MjKbphqlGMpcEbg2vRDf68N Wj5w== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:sender:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:to:from :wdcironportexception:ironport-sdr:ironport-sdr:ironport-sdr :dkim-signature; bh=vuxswliKTubVP8of6YVTD5ezN8kSxgXpPUoFQqnYn6g=; b=Usw2GA2WI1tgCq9hoh1Iv4m8f8gXOHhPT6/3qgteJoGyIz8reWuEyjCZ34ycS07tS7 pQ/siBFh5gVfZVT0CpKhqbXIVPn3wmfeB5st39lIEV5AshJyv5VNktKXcIf+gdzh6SDT TqBDIftyBL8kSNk43FNdxMmo1xf8zYuNv+CKuFhF7H/x0wydewjUp4lHCeSOSlwl065C wzbASvyNjqPaD/sGpGdJhD3CC1jGQLB0BHuKvOgQx90Xr3vLLJHhCb9+xpW//+b9PkHE GYjooWUPKKhBJFBDUD6lrbR1o1i5nCJDkbcFSkvmwAqrQ9LMvHYkt8/WazuP3ZzQiRHz /OKw== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=Dok3zDix; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Return-Path: Received: from vger.kernel.org (vger.kernel.org. [209.132.180.67]) by mx.google.com with ESMTP id h3si2368642otm.254.2020.03.17.18.13.35; Tue, 17 Mar 2020 18:13:48 -0700 (PDT) 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=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=Dok3zDix; 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; dmarc=fail (p=NONE sp=NONE dis=NONE) header.from=wdc.com Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1727487AbgCRBMI (ORCPT + 99 others); Tue, 17 Mar 2020 21:12:08 -0400 Received: from esa5.hgst.iphmx.com ([216.71.153.144]:45921 "EHLO esa5.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727368AbgCRBMC (ORCPT ); Tue, 17 Mar 2020 21:12:02 -0400 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1584493922; x=1616029922; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=6XwVtd4hjdLAdDULSYiiivE6I4tNnePY/rn/fOEMUu4=; b=Dok3zDixeMBRs7r3k0mctfGjad8EbmTAwIHARCUA6bC2IkD2ZNk3DEmD sAepvUSY8NGH4UyBYxUQnsrmWQsMsMdW8Akh+H6Y8u7JW+TVIgJvrzHPV 7A0tlAmeLiK/+MpnL4LNo6GOB6f25+VJNwNnAiT90p7TZahWpv0sAgitx DLSfVCR+3Hvi6aIVN36jKh/5F24VFHGghost+yD23X6QVonKhkOejCb7L q7A9Zo2iVARBovf0iFpFNkws9w8lbmBk4I4o5d3V+ztW0IzmDIf2jtUyO XusIEcvU4BOZ33zmckY+f2nw4BtqFnRzYIQ6DqivuCNqm4SsvmatJF1M7 Q==; IronPort-SDR: FoaECZX0M03bA9ET9sfwpAl6fSoXoJ4qpGl0dMWg568HCIQF6/51GDemA6mYqrgiauWfWjyzv3 Psac2OepQttHvZ650J78C5AWxMijbULbhGngzre1qMNJovMtU6qWV1Lwi0n43X1fgP9Pv7KzK2 8jorhJzSpES7X6eiODF9gojFvdepdGyillFgudfaKNlA3xo++4Dh3rR1W/KCgm/Jn6UCiHdMfB z4C33uq4Q8bbJ2i9n1baDL+TEFGx9+krtOjKZRfLdV6/doHYAv6nktk9H71p7sVqDxi6JMs3zM wwI= X-IronPort-AV: E=Sophos;i="5.70,565,1574092800"; d="scan'208";a="133241535" Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 18 Mar 2020 09:12:02 +0800 IronPort-SDR: JH2mRhTOvP0QAZOLaga9Ga9MKHlivaCABFOT72nXZDUOfNU5k+mlP9/f85wgY0MnGcCqU9yy95 ztG8VbitTnrxeRE/qZB2gD8LCKbF9BcAnQy1xLzHgTS+rQbKm1ohwpTtNvC/EIhYeWXXyQgTty SVgDV92KZZua/j5t/CEUy9GfmAywqfeyf1IYfzP8kw3BhQQ838V4CBIGH2warcEu1In7l1yQWz lofKxTSN0aUQE2zwnJqNnAPyQqJ+Ygjyh8gO7Qv4GdgUSViDomCvrHSwRnpV1zsLRtTVgJSZoY Wja1eh1vH7od2D4OWYXVXlLn Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 17 Mar 2020 18:03:52 -0700 IronPort-SDR: o9JDJg+S4/mv3uQOWj+ifTAHQHQdygp45KaVQHxiyWTNMjk1EFPiqy42FM0B+NbL38uK313F/p SFSRhLIcvIx65mwxWAi8tPUEbM32LDmTTiWbE1sVlPQTripVNLaYv+A6V2YxkmOre8zpMqkQhq NuRm7W8T/x9N1xWruUFH0aOXvEwXobQz1rmpGSkkY7XUXqcHI2y0gfZS0MEuyKPme0vIDz4Xlp +caEo60cf8Rne4ZSoCQ5PljzG36fE1xOR9hjHYU8s5ZIEozE2jWQsGeZPcx41S8cLwNo9FvJc6 6/E= WDCIronportException: Internal Received: from mccorma-lt.ad.shared (HELO yoda.hgst.com) ([10.86.54.125]) by uls-op-cesaip01.wdc.com with ESMTP; 17 Mar 2020 18:12:01 -0700 From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Anup Patel , Albert Ou , Gary Guo , Greentime Hu , linux-riscv@lists.infradead.org, Mao Han , Mike Rapoport , Nick Hu , Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Vincent Chen , Zong Li , Bin Meng Subject: [PATCH v11 10/11] RISC-V: Add supported for ordered booting method using HSM Date: Tue, 17 Mar 2020 18:11:43 -0700 Message-Id: <20200318011144.91532-11-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20200318011144.91532-1-atish.patra@wdc.com> References: <20200318011144.91532-1-atish.patra@wdc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit Sender: linux-kernel-owner@vger.kernel.org Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org 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 Reviewed-by: Anup Patel --- arch/riscv/kernel/Makefile | 3 ++ arch/riscv/kernel/cpu_ops.c | 10 +++- arch/riscv/kernel/cpu_ops_sbi.c | 81 +++++++++++++++++++++++++++++++++ arch/riscv/kernel/head.S | 26 +++++++++++ arch/riscv/kernel/smpboot.c | 2 +- arch/riscv/kernel/traps.c | 2 +- 6 files changed, 121 insertions(+), 3 deletions(-) create mode 100644 arch/riscv/kernel/cpu_ops_sbi.c diff --git a/arch/riscv/kernel/Makefile b/arch/riscv/kernel/Makefile index f81a6ff88005..a0be34b96846 100644 --- a/arch/riscv/kernel/Makefile +++ b/arch/riscv/kernel/Makefile @@ -44,5 +44,8 @@ obj-$(CONFIG_PERF_EVENTS) += perf_event.o obj-$(CONFIG_PERF_EVENTS) += perf_callchain.o obj-$(CONFIG_HAVE_PERF_REGS) += perf_regs.o obj-$(CONFIG_RISCV_SBI) += sbi.o +ifeq ($(CONFIG_RISCV_SBI), y) +obj-$(CONFIG_SMP) += cpu_ops_sbi.o +endif clean: diff --git a/arch/riscv/kernel/cpu_ops.c b/arch/riscv/kernel/cpu_ops.c index 62705908eee5..c4c33bf02369 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,5 +35,12 @@ void cpu_update_secondary_bootdata(unsigned int cpuid, void __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; } diff --git a/arch/riscv/kernel/cpu_ops_sbi.c b/arch/riscv/kernel/cpu_ops_sbi.c new file mode 100644 index 000000000000..66f3cded91f5 --- /dev/null +++ b/arch/riscv/kernel/cpu_ops_sbi.c @@ -0,0 +1,81 @@ +// SPDX-License-Identifier: GPL-2.0-only +/* + * HSM extension and cpu_ops implementation. + * + * Copyright (c) 2020 Western Digital Corporation or its affiliates. + */ + +#include +#include +#include +#include +#include + +extern char secondary_start_sbi[]; +const struct cpu_operations cpu_ops_sbi; + +static int sbi_hsm_hart_start(unsigned long hartid, unsigned long saddr, + unsigned long priv) +{ + struct sbiret ret; + + ret = sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_START, + hartid, saddr, priv, 0, 0, 0); + if (ret.error) + return sbi_err_map_linux_errno(ret.error); + else + return 0; +} + +#ifdef CONFIG_HOTPLUG_CPU +static int sbi_hsm_hart_stop(void) +{ + struct sbiret ret; + + ret = sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_STOP, 0, 0, 0, 0, 0, 0); + + if (ret.error) + return sbi_err_map_linux_errno(ret.error); + else + return 0; +} + +static int sbi_hsm_hart_get_status(unsigned long hartid) +{ + struct sbiret ret; + + ret = sbi_ecall(SBI_EXT_HSM, SBI_EXT_HSM_HART_STATUS, + hartid, 0, 0, 0, 0, 0); + if (ret.error) + return sbi_err_map_linux_errno(ret.error); + else + return ret.value; +} +#endif + +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 173507395a6b..e5115d5e0b3a 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 e89396a2a1af..4e9922790f6e 100644 --- a/arch/riscv/kernel/smpboot.c +++ b/arch/riscv/kernel/smpboot.c @@ -143,7 +143,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 ffb3d94bf0cc..8e13ad45ccaa 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.25.1