Received: by 2002:a25:c205:0:0:0:0:0 with SMTP id s5csp330239ybf; Wed, 26 Feb 2020 14:03:10 -0800 (PST) X-Google-Smtp-Source: APXvYqyTJ3yXOvV5S7q+lx7VZTS6436ZxXLonTUwRID3lgaZBAouzHBnxbOc74Sms4cbj2upeKJh X-Received: by 2002:aca:ad11:: with SMTP id w17mr942380oie.85.1582754589970; Wed, 26 Feb 2020 14:03:09 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1582754589; cv=none; d=google.com; s=arc-20160816; b=yFUGymzszwBEec5oUwLpbmwwxLyp6YwAmlA+usZCHhXrNvYLBlvUtCHoljU2hkl/Fz 8DV7EOGrJ3d7xsa9KGFHvRkaw2X39RFc6Naqo8DWTOh0+M966wYI0ePmfEbC3XCwihQ6 CWC4UFQNbHLhOHWOqvPAEP8WoQuC4PhZf+PPiW0lx3MozhxZJe2CBfjzlACjlEVQxetc p5pwlfDkbY+VJqQZC8KCmcOhHKwdORlXEPqXXPs8JgsLi127QiYeIJDPuVu5CnsdvlA8 aaVEqkPuiLcRkAzDB4juj/lMhIOTJ+yBEO4a1VjVRRH4WGQ9igiKZA92HSijIHsVnsfn ZGrQ== 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=QP/7Hmzuy55zFPDrv5rYCEb1TKFrYfnt7THOVTNwwH8=; b=xl3NgZLeyp5Ho6V71iIMmzghKfBGwfw2+vhmdiSvey9hPDII10EYMO9UUkQdgNWMuU gK8eYsNDwY/5mBowHRp3lG2ZgTenBATG/a0s5wOokbpcVaPEwLzmbi0jPjVetyYxwcnA Pn4G+ARnZ01JkRqSrHwrO3aNLv37seg/Q8rNk6Lsh9STbT1dl1IaPonCduWBQZatYXB0 10tpliiKJpySMKfqLn1HAM+24yPQniXOHPveboJUf9CDxRUSGfIbcKfU62XOI2jjJoYn v+rrwZwyc2pIENOiAEnaVIFN0JJA+PoUr8Tn/ikUKDXusDf1cHiibIt+b7UDQRhFzCdF l9rQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=TkndZSPh; 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 c67si280133oib.276.2020.02.26.14.02.57; Wed, 26 Feb 2020 14:03:09 -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=fail header.i=@wdc.com header.s=dkim.wdc.com header.b=TkndZSPh; 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 S1727938AbgBZWCb (ORCPT + 99 others); Wed, 26 Feb 2020 17:02:31 -0500 Received: from esa6.hgst.iphmx.com ([216.71.154.45]:45045 "EHLO esa6.hgst.iphmx.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1727894AbgBZWC1 (ORCPT ); Wed, 26 Feb 2020 17:02:27 -0500 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1582754547; x=1614290547; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=U35XF1CKYWzhgzuZboVKa7NT7J12Ff9SA644B0PoBj4=; b=TkndZSPhzydBCt+7xmuLzcGJUSY+tagrkn4OmQ6ky4X/2AmOw5FsOOtg oiETnCGt21CCMehpeCgB2bHt2D2G7cYKwjkpV6O/1h0wJqdYJF49XZ65Q Ofu4xoS/Jv7rnNAqGxfDBs0zrOVjUgvtn68SQ7BS3xb0aSzPi07EiuoOX b62vfivMLIspvRINiMj/rp5RovsYGSQTxMEXF2EPiAUm4mh88Z70HvDHU 98CMo9IBuvG1INbfhlrLu2OKcElQ9SVDdfJ2SDdZrSCkORhAfxD4S3mya EdqNaLmUz2b/SrWuzZ3yniHG0wQQ4eF7wLto5PGG2H2roRCPTTHiSgy0M g==; IronPort-SDR: M9N5qPCsC8rKQwYZMpmcm+97GZ565duaTv0saHtC9UaMWbT1rNZ074S7Q0Ci0kn8faqJHlimLw Ff0o72QytiNFBVanWRFAo8hBKx/5RK4Lwpr9r/+fN85Q+L+TOkuIi7PJzq7FBuxhqujJcOK2eZ Ptql+pldUrL4lCBilosoG/ipkLeXlNluxvJ8MuLGmRjoBufLaK7/IFTh0N+mSqgk4P0Xr/msBX b0C6Uyfhqpe7cnQbPbyUO/qioEnSrS7abjVhb9cc2zh0oGf5U4dZMSXSDxxja0GDgk5smZIOc5 hKA= X-IronPort-AV: E=Sophos;i="5.70,489,1574092800"; d="scan'208";a="132290751" Received: from uls-op-cesaip01.wdc.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 27 Feb 2020 06:02:26 +0800 IronPort-SDR: Y1bDgGjRJysaGPgx3yaBdbSz1K6yla9MaSmKmMMj86Z4XiSn2J3WnNac1Gutxg/BY/9DxdntqH qY9BMFxOQme4hdmOX2w+pq1N8UayBDuAkuo/fd53jIpHiJOpyLOk+ozUMPs+NhaD+VafrfreD6 gkNdJczExrj4D3F0D8KdZvmnfzoTBNCSY2STDgn6pIG4uBq/TDpDzNrzJkA9s4S6D8ryN+CaAJ jqK7PddEK8TM5kMsVDfFn4kYEYfCAf/U7GixJ4W+yCBAYvw0HhnJoYXSCez6UBkesFat1LYikX LQZLwvjfyUsBJSI31ZouqiMt Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 26 Feb 2020 13:54:50 -0800 IronPort-SDR: MChZIQlV3kwaNbOdz59YG+WCoUltZSHgUoYSW1LtcIx9y9LNcojbjRpcXKJMRVdbQVeGoFwvI7 gPipAKxPAkyJqAu++DTcXJuY90eJZgbyFuOkrsFiaLbrxR6CHPS72+CJV4sDhwt8J+41dlj8kI JuKpTS5nPm2CuX5tzHYuGxQt2YQlP2fDZxf6MN8CDVzic3qK3imZ2Um4bCiYup7N853Wxc2LT1 +AV2G03cz9ZSLaOFgU/eZI8v1GP0MV3d+mt0KL25UDtswjlNlvudG/50/wwzyUjs+8KgIcTkDB oBo= WDCIronportException: Internal Received: from yoda.sdcorp.global.sandisk.com (HELO yoda.int.fusionio.com) ([10.196.158.80]) by uls-op-cesaip02.wdc.com with ESMTP; 26 Feb 2020 14:02:25 -0800 From: Atish Patra To: linux-kernel@vger.kernel.org Cc: Atish Patra , Anup Patel , Albert Ou , Alexios Zavras , Borislav Petkov , Daniel Jordan , "Eric W. Biederman" , Gary Guo , Geert Uytterhoeven , Greentime Hu , Greg Kroah-Hartman , Heiko Carstens , Jason Cooper , Kate Stewart , Kees Cook , linux-riscv@lists.infradead.org, Madhavan Srinivasan , Mao Han , Marc Zyngier , Michael Kelley , Mike Rapoport , Nick Hu , Palmer Dabbelt , Paul Walmsley , "Rafael J. Wysocki" , Steven Price , Sudeep Holla , Thomas Gleixner , Vincent Chen , Zong Li Subject: [PATCH v10 10/12] RISC-V: Add supported for ordered booting method using HSM Date: Wed, 26 Feb 2020 14:02:11 -0800 Message-Id: <20200226220213.27423-11-atish.patra@wdc.com> X-Mailer: git-send-email 2.25.0 In-Reply-To: <20200226220213.27423-1-atish.patra@wdc.com> References: <20200226220213.27423-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 e950ae5bee9c..afa90f711a2b 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..70d02dfe0ab8 --- /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 b85376d84098..ac5b0e0a02f6 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.0