Received: by 2002:a25:8b91:0:0:0:0:0 with SMTP id j17csp9415ybl; Mon, 27 Jan 2020 20:56:53 -0800 (PST) X-Google-Smtp-Source: APXvYqzYdmz46RuEvps5hZE2NkAU1UL4bL0kt+bCPWjFdEWgziNZbmp21G2UAPTDuKq8s8xcP+6q X-Received: by 2002:a54:4086:: with SMTP id i6mr1729351oii.65.1580187413089; Mon, 27 Jan 2020 20:56:53 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1580187413; cv=none; d=google.com; s=arc-20160816; b=hh2aOyBIZVVOwdvqa71OkD8zfIcEE1o+43b0GUgTxhvGKzZiq11JK6b1moQ7MrmQV5 XTNY0PtvvgachGldpZ0qB9u4gLoonfVpDvBqDZlG5AkL1og44Abc4khidtZNRSvGucOU 7eJwgR3y7AyN8dmmvVO3/qfnqlBhChBvtoewnb0FbKK4sLidiBaXUXNehwLGj3sKYAI8 kCZ88fZTyQS74MjZvw6gA0niC1oZBkoWhgJM+H9aW32HVG5kjbUNiZwh1teq/rex3Vt7 S2VFhUy5YiQfSZfEItVhhG99COAVRfV9E+fnbcq7hanvGvapw/RCFn+Gds4X6W3+IWYp rI5A== 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=6npXOuD/Bo9Epv5uCeYToBPL1sbhP+ZtGVUUhP+lSl4=; b=wO5qY5nVPBmmm8nhBC2ag/TMWb4Pvpz7i0c/SxMznqtLjx8NakhlLXa90YEdrD4RBZ qTxWSEjdWbQ742c/pDHBy0qyCf2EBIPUAjkQo0z6KQBRuV/Fet+rRXg6JFKSSM9Oi+Gf C6phbzgRbrz22ec249yJoNr3hRPgExFZOIW+P2nhSaJ8xKzcwfndHe9ZsJ7Uz05djIf1 6V61OW5mOt7QqaxwtmDtYPibhahFAF0gbI++kktWhYmTj8JiISGrdFaHgVrRt+wy4ol/ S52G2a92I65qeW89s3XKMe4vIGkRfsoNZdXSk9NhkZL80O+GN1k+SL7w+lPfl3fvBUJU xX/g== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@brainfault-org.20150623.gappssmtp.com header.s=20150623 header.b="FMGXr3/X"; 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 l11si3800359otn.189.2020.01.27.20.56.34; Mon, 27 Jan 2020 20:56:53 -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="FMGXr3/X"; 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 S1726296AbgA1Eyy (ORCPT + 99 others); Mon, 27 Jan 2020 23:54:54 -0500 Received: from mail-wr1-f67.google.com ([209.85.221.67]:44066 "EHLO mail-wr1-f67.google.com" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1726080AbgA1Eyy (ORCPT ); Mon, 27 Jan 2020 23:54:54 -0500 Received: by mail-wr1-f67.google.com with SMTP id q10so14434200wrm.11 for ; Mon, 27 Jan 2020 20:54:51 -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=6npXOuD/Bo9Epv5uCeYToBPL1sbhP+ZtGVUUhP+lSl4=; b=FMGXr3/X5d5MGN25hhpmHA0I89Je2TlY/luDe2ZDEyCBgWWLoS+USu2m9mWi6jIcDC CxpOLgkwdzLc5sLd4Ei2ZQYzU+OowUfHLM3nxn2E4q2VPaBV4W+5jBxyRZt1imd6O1QT njuUqLVVgLpOZLoYRPwBAo9HFifDcmyFuKTPyVI2HbbBCmDmj5c+/uaYqOFtD2UkWwAJ Z9DaVA4ml/+j43chulho0QtwQ+QhB+DMRWJFQ62sWaBvuh4MXmTTNseGTCuDkUW2G1lR /o81IkQ0lVL4L5TWP8yECxzfZqKmdMqPM6d0jpMUofOLmyyd7YiG2Ix04ue30OZR5MRs B/kQ== 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=6npXOuD/Bo9Epv5uCeYToBPL1sbhP+ZtGVUUhP+lSl4=; b=PWRDzc6sFsXaA2KbuHz1YJHFVNdQhXGhQh+9BeW+WQenr8LxrBTofslwu+vIJGqT+a Lu6kQgDGmS/DbZk92UU3H4bPFEgpEnVeMVyhMRZP1HFQKGptKXI0Ie+HJs66iLtiN00E B8wB2GiRIj0rMnfCo7YlA4qdXXHEFKZ1Dxl2z2dCJPFOUzDR2hXAG9nWKW1xVSkpkKYp EPEbQ9+d7kM8cbS23cmQOS5i/42yt9A/AgpsuSKjQn3cktLFlBPj3OuOEVAEN+DfyIm0 iJqvcx3ppARdJOkNXEP6upRfPCXH8OPsuc5OpObsqadf1RPcfz2jmnBxDisu8q5VGvja FrXg== X-Gm-Message-State: APjAAAUwo1fNKirt4LuDlfRozWbFwY31+1rf6CbMMGsKmDdOyZTtr5rq FlPFj6AkFlIkCP+4JGM2wC1r+BpamPlgXP2MqghTxw== X-Received: by 2002:a5d:538e:: with SMTP id d14mr26992846wrv.358.1580187290925; Mon, 27 Jan 2020 20:54:50 -0800 (PST) MIME-Version: 1.0 References: <20200128022737.15371-1-atish.patra@wdc.com> <20200128022737.15371-9-atish.patra@wdc.com> In-Reply-To: <20200128022737.15371-9-atish.patra@wdc.com> From: Anup Patel Date: Tue, 28 Jan 2020 10:24:39 +0530 Message-ID: Subject: Re: [PATCH v7 08/10] RISC-V: Add SBI HSM extension To: Atish Patra Cc: "linux-kernel@vger.kernel.org List" , Albert Ou , Borislav Petkov , "Eric W. Biederman" , Geert Uytterhoeven , Greentime Hu , Greg Kroah-Hartman , Heiko Carstens , Kees Cook , linux-riscv , Mao Han , Mike Rapoport , Palmer Dabbelt , Paul Walmsley , Thomas Gleixner , Vincent Chen , Abner Chang , Chester Lin , nickhu@andestech.com, Palmer Dabbelt 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, Jan 28, 2020 at 7:58 AM Atish Patra wrote: > > SBI specification defines HSM extension that allows to start/stop a hart > by a supervisor anytime. The specification is available at > > https://github.com/riscv/riscv-sbi-doc/blob/master/riscv-sbi.adoc > > Implement SBI HSM extension. > > Signed-off-by: Atish Patra > --- > arch/riscv/include/asm/sbi.h | 22 ++++++++++++++++ > arch/riscv/kernel/sbi.c | 51 ++++++++++++++++++++++++++++++++++++ > 2 files changed, 73 insertions(+) > > diff --git a/arch/riscv/include/asm/sbi.h b/arch/riscv/include/asm/sbi.h > index d55d8090ab5c..bed6fa26ec84 100644 > --- a/arch/riscv/include/asm/sbi.h > +++ b/arch/riscv/include/asm/sbi.h > @@ -26,6 +26,7 @@ enum sbi_ext_id { > SBI_EXT_TIME = 0x54494D45, > SBI_EXT_IPI = 0x735049, > SBI_EXT_RFENCE = 0x52464E43, > + SBI_EXT_HSM = 0x48534D, > }; > > enum sbi_ext_base_fid { > @@ -56,6 +57,12 @@ enum sbi_ext_rfence_fid { > SBI_EXT_RFENCE_REMOTE_HFENCE_VVMA_ASID, > }; > > +enum sbi_ext_hsm_fid { > + SBI_EXT_HSM_HART_START = 0, > + SBI_EXT_HSM_HART_STOP, > + SBI_EXT_HSM_HART_STATUS, > +}; > + I think we should also define the possible return values of SBI_EXT_HSM_HART_STATUS function. > #define SBI_SPEC_VERSION_DEFAULT 0x1 > #define SBI_SPEC_VERSION_MAJOR_SHIFT 24 > #define SBI_SPEC_VERSION_MAJOR_MASK 0x7f > @@ -70,6 +77,7 @@ enum sbi_ext_rfence_fid { > #define SBI_ERR_INVALID_ADDRESS -5 > > extern unsigned long sbi_spec_version; > +extern bool sbi_hsm_avail; > struct sbiret { > long error; > long value; > @@ -110,8 +118,18 @@ int sbi_remote_hfence_vvma_asid(const unsigned long *hart_mask, > unsigned long start, > unsigned long size, > unsigned long asid); > +int sbi_hsm_hart_start(unsigned long hartid, unsigned long saddr, > + unsigned long priv); > +int sbi_hsm_hart_stop(void); > +int sbi_hsm_hart_get_status(unsigned long hartid); > + > int sbi_probe_extension(int ext); > > +static inline bool sbi_hsm_is_available(void) > +{ > + return sbi_hsm_avail; > +} > + > /* Check if current SBI specification version is 0.1 or not */ > static inline int sbi_spec_is_0_1(void) > { > @@ -137,5 +155,9 @@ void sbi_clear_ipi(void); > void sbi_send_ipi(const unsigned long *hart_mask); > void sbi_remote_fence_i(const unsigned long *hart_mask); > void sbi_init(void); > +static inline bool sbi_hsm_is_available(void) > +{ > + return false; > +} > #endif /* CONFIG_RISCV_SBI */ > #endif /* _ASM_RISCV_SBI_H */ > diff --git a/arch/riscv/kernel/sbi.c b/arch/riscv/kernel/sbi.c > index 3c34aba30f6f..9bdc9801784d 100644 > --- a/arch/riscv/kernel/sbi.c > +++ b/arch/riscv/kernel/sbi.c > @@ -12,6 +12,8 @@ > > /* default SBI version is 0.1 */ > unsigned long sbi_spec_version = SBI_SPEC_VERSION_DEFAULT; > +bool sbi_hsm_avail; > + > EXPORT_SYMBOL(sbi_spec_version); > > static void (*__sbi_set_timer)(uint64_t stime); > @@ -496,6 +498,54 @@ static void sbi_power_off(void) > sbi_shutdown(); > } > > +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 ret.value; > + else > + return sbi_err_map_linux_errno(ret.error); > +} > +EXPORT_SYMBOL(sbi_hsm_hart_stop); > + > +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 ret.value; > + else > + return sbi_err_map_linux_errno(ret.error); > +} > +EXPORT_SYMBOL(sbi_hsm_hart_start); > + > +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 ret.value; > + else > + return sbi_err_map_linux_errno(ret.error); > +} > +EXPORT_SYMBOL(sbi_hsm_hart_get_status); > + > +void __init sbi_hsm_ext_init(void) > +{ > + if (sbi_probe_extension(SBI_EXT_HSM) > 0) { > + pr_info("SBI v0.2 HSM extension detected\n"); > + sbi_hsm_avail = true; > + } > +} > + If we start adding all present and future extensions in arch/riscv/kernel/sbi.c then it will blow-up. IMHO, we should only keep legacy and replacement extension in arch/riscv/kernel/sbi.c. All other extensions will be separate based on how they are integrated. For SBI HSM, all sbi_hsm_xyz() functions should be in arch/riscv/kernel/cpu_ops_sbi.c which will be only compiled when CONFIG_RISCV_SBI is enabled. Maybe merge PATCH8 and PATCH9 ? Regards, Anup > int __init sbi_init(void) > { > int ret; > @@ -532,5 +582,6 @@ int __init sbi_init(void) > __sbi_rfence = __sbi_rfence_v01; > } > > + sbi_hsm_ext_init(); We don't need sbi_hsm_ext_init() because we can check and set CPU ops at boot-time in cpu_set_ops() > return 0; > } > -- > 2.24.0 > Regards, Anup