From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from kanga.kvack.org (kanga.kvack.org [205.233.56.17]) by smtp.lore.kernel.org (Postfix) with ESMTP id 2B753C433FE for ; Fri, 4 Nov 2022 04:10:35 +0000 (UTC) Received: by kanga.kvack.org (Postfix) id 9746C6B0071; Fri, 4 Nov 2022 00:10:34 -0400 (EDT) Received: by kanga.kvack.org (Postfix, from userid 40) id 9242F8E0001; Fri, 4 Nov 2022 00:10:34 -0400 (EDT) X-Delivered-To: int-list-linux-mm@kvack.org Received: by kanga.kvack.org (Postfix, from userid 63042) id 7F4CB6B0074; Fri, 4 Nov 2022 00:10:34 -0400 (EDT) X-Delivered-To: linux-mm@kvack.org Received: from relay.hostedemail.com (smtprelay0013.hostedemail.com [216.40.44.13]) by kanga.kvack.org (Postfix) with ESMTP id 713436B0071 for ; Fri, 4 Nov 2022 00:10:34 -0400 (EDT) Received: from smtpin26.hostedemail.com (a10.router.float.18 [10.200.18.1]) by unirelay01.hostedemail.com (Postfix) with ESMTP id 3FE281C6EE6 for ; Fri, 4 Nov 2022 04:10:34 +0000 (UTC) X-FDA: 80094433188.26.E061271 Received: from mail-pl1-f170.google.com (mail-pl1-f170.google.com [209.85.214.170]) by imf27.hostedemail.com (Postfix) with ESMTP id A071040005 for ; Fri, 4 Nov 2022 04:10:32 +0000 (UTC) Received: by mail-pl1-f170.google.com with SMTP id io19so3811979plb.8 for ; Thu, 03 Nov 2022 21:10:32 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :from:to:cc:subject:date:message-id:reply-to; bh=fi8KcnFgLbFZn4EmtIrVW3sFxfc7iM4ws8KRz12zBS4=; b=l16k8LJt9UMqD+W/3FB6PKWbn0gqNL76Ueik7fMpM+9CpMMKDd6LN2D/gnMt/cXWmi LtKA4bpEtTWF+qX7Fh91GatmXqQnBErF/wTEqhjnGralWWQ8phIwMETnbTUPCp5naZeG 9GLVGt9ArlkZaHHe1f22GtX2prKrjo6DAyhkq41KGg2TFJUcp8tyhL7j4ir3hDjH7zT5 9g8vSO7y1gjVF9XIdCkYo7NMuIQV/OLqtETihNbsBSNb1Nx9/7i5RsVIhcCYnHiYwwtK SyNtKckjo33Qi8R3Gjse/YEr6iZc1zZF9eOxHnnRVKFoMwCVpYBehnIcmroPu5ug16ql CECg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:in-reply-to:from:references:cc:to :content-language:subject:user-agent:mime-version:date:message-id :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=fi8KcnFgLbFZn4EmtIrVW3sFxfc7iM4ws8KRz12zBS4=; b=fxkxtYhsf7PKobnlcr9urErG4peFoxuqg5aILIhRgiELh4QBT2+EK2gtK9JLu4TroK /OmbnK3csKdSz1BFQR45pggzTs0FPdfxWUuH7VaC6BUg+jR2/ECw/jXmUzSc2d5RdMua G/ZE4coMGgqgXjupJjH20MqoesGtRoEEnalOm/hmk60mp3lYIcojxW08cCjF5w949Je7 aK4ELao4kMSxx8deK47yx5kljhQlKY7hAq7FjO9v6NjOxGzpzIhP3NJzUyJ6rUjTXaiY +gxFmnF4uIXoRp1hSQAwYrf+PZCpf+vODLaAgV+XxEbytlTRB0WrR01efvqMCmmyL11C rrIw== X-Gm-Message-State: ACrzQf0wGn+4M8dS+ZENfHuFuURivCkohnz8aCACFXfAL0ov2IY5K6FG /pjvdBtZwAh9jYzmvi5UZMB1aQ== X-Google-Smtp-Source: AMsMyM4Ya+CXIjZNB6gKQeMTnbbAArqDDLdxjQ1rMBze3JIfgZTXPhlFM2cIAxEifnm0xw7LqleDfQ== X-Received: by 2002:a17:902:e888:b0:186:a6be:1106 with SMTP id w8-20020a170902e88800b00186a6be1106mr33073935plg.150.1667535031546; Thu, 03 Nov 2022 21:10:31 -0700 (PDT) Received: from [192.168.50.116] (c-24-4-73-83.hsd1.ca.comcast.net. [24.4.73.83]) by smtp.gmail.com with ESMTPSA id z11-20020a1709027e8b00b001869f2120absm1382409pla.294.2022.11.03.21.10.28 (version=TLS1_3 cipher=TLS_AES_128_GCM_SHA256 bits=128/128); Thu, 03 Nov 2022 21:10:30 -0700 (PDT) Message-ID: Date: Thu, 3 Nov 2022 21:10:28 -0700 MIME-Version: 1.0 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:102.0) Gecko/20100101 Thunderbird/102.2.2 Subject: Re: [PATCH v12 05/17] riscv: Add has_vector/riscv_vsize to save vector features. Content-Language: en-US To: Chris Stillson Cc: Greentime Hu , Guo Ren , Vincent Chen , Paul Walmsley , Palmer Dabbelt , Albert Ou , Eric Biederman , Kees Cook , Anup Patel , Atish Patra , Oleg Nesterov , Guo Ren , Heinrich Schuchardt , Arnaud Pouliquen , Paolo Bonzini , Alexandre Ghiti , Arnd Bergmann , Heiko Stuebner , Jisheng Zhang , Dao Lu , Sunil V L , linux-riscv , lkml , linux-mm@kvack.org References: <20220921214439.1491510-1-stillson@rivosinc.com> <20220921214439.1491510-5-stillson@rivosinc.com> From: Vineet Gupta In-Reply-To: <20220921214439.1491510-5-stillson@rivosinc.com> Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit ARC-Seal: i=1; s=arc-20220608; d=hostedemail.com; t=1667535032; a=rsa-sha256; cv=none; b=6M/ODVsgqj1cqBpdLmVS/kRzlbskjJrd97xbdTfbOTMnxcpw0FnFRWYVD5bbHyQefSD9gu OrDeiRuBHK1H45F9bnbku43mZ/VY6oxu1Fm5jNcySrI1lglsnrJ8Kv+PSVBzEaGefqE18q wxFH5pOw6//eCSoMum98T3OgFmtw8nA= ARC-Authentication-Results: i=1; imf27.hostedemail.com; dkim=pass header.d=rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=l16k8LJt; spf=pass (imf27.hostedemail.com: domain of vineetg@rivosinc.com designates 209.85.214.170 as permitted sender) smtp.mailfrom=vineetg@rivosinc.com; dmarc=none ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=hostedemail.com; s=arc-20220608; t=1667535032; h=from:from:sender:reply-to:subject:subject:date:date: message-id:message-id:to:to:cc:cc:mime-version:mime-version: content-type:content-type: content-transfer-encoding:content-transfer-encoding: in-reply-to:in-reply-to:references:references:dkim-signature; bh=fi8KcnFgLbFZn4EmtIrVW3sFxfc7iM4ws8KRz12zBS4=; b=Lks/GoNEsyc6fy/SKfvPC2gJSTlkTlX/nDZK2H4XYZN205zj/LHyPi80OJbQ1b31DiPHXR nj5rkHZH2JDfQjjvNO0ujEBKWdCu9cxkQW5Q10dPcmq0lPPprB1qd9KXNPDUGaIAjmuqNT B+fq4W/MR26eaocZHHbp8RSU2yz3VJE= X-Stat-Signature: yg7reymyjxnn47563ikc1z4k9gii9b3f X-Rspamd-Server: rspam09 X-Rspam-User: X-Rspamd-Queue-Id: A071040005 Authentication-Results: imf27.hostedemail.com; dkim=pass header.d=rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=l16k8LJt; spf=pass (imf27.hostedemail.com: domain of vineetg@rivosinc.com designates 209.85.214.170 as permitted sender) smtp.mailfrom=vineetg@rivosinc.com; dmarc=none X-HE-Tag: 1667535032-294330 X-Bogosity: Ham, tests=bogofilter, spamicity=0.000000, version=1.2.4 Sender: owner-linux-mm@kvack.org Precedence: bulk X-Loop: owner-majordomo@kvack.org List-ID: On 9/21/22 14:43, Chris Stillson wrote: > From: Greentime Hu > > This patch is used to detect vector support status of CPU and use > riscv_vsize to save the size of all the vector registers. It assumes > all harts has the same capabilities in SMP system. Patch title is horrible. The meat of patch is vector state save/restore, but no users of it yet. And then there are random unrelated snippets thrown in same patch. > > [guoren@linux.alibaba.com: add has_vector checking] > Co-developed-by: Guo Ren > Signed-off-by: Guo Ren > Co-developed-by: Vincent Chen > Signed-off-by: Vincent Chen > Signed-off-by: Greentime Hu > --- > arch/riscv/include/asm/vector.h | 14 +++++ > arch/riscv/kernel/cpufeature.c | 19 +++++++ > arch/riscv/kernel/riscv_ksyms.c | 6 +++ > arch/riscv/kernel/vector.S | 93 +++++++++++++++++++++++++++++++++ > 4 files changed, 132 insertions(+) > create mode 100644 arch/riscv/include/asm/vector.h > create mode 100644 arch/riscv/kernel/vector.S > > diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h > new file mode 100644 > index 000000000000..16304b0c6a6f > --- /dev/null > +++ b/arch/riscv/include/asm/vector.h > @@ -0,0 +1,14 @@ > +/* SPDX-License-Identifier: GPL-2.0-or-later */ > +/* > + * Copyright (C) 2020 SiFive > + */ > + > +#ifndef __ASM_RISCV_VECTOR_H > +#define __ASM_RISCV_VECTOR_H > + > +#include > + > +void rvv_enable(void); > +void rvv_disable(void); > + > +#endif /* ! __ASM_RISCV_VECTOR_H */ > diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c > index 8d4448c2d4f4..0487ab19b234 100644 > --- a/arch/riscv/kernel/cpufeature.c > +++ b/arch/riscv/kernel/cpufeature.c > @@ -30,6 +30,14 @@ static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly; > > __ro_after_init DEFINE_STATIC_KEY_ARRAY_FALSE(riscv_isa_ext_keys, RISCV_ISA_EXT_KEY_MAX); > EXPORT_SYMBOL(riscv_isa_ext_keys); > +#ifdef CONFIG_FPU > +__ro_after_init DEFINE_STATIC_KEY_FALSE(cpu_hwcap_fpu); > +#endif This needs to be broken out to a FPU patch which actually uses cpu_hwcap_fpu. > +#ifdef CONFIG_VECTOR > +#include > +__ro_after_init DEFINE_STATIC_KEY_FALSE(cpu_hwcap_vector); > +unsigned long riscv_vsize __read_mostly; > +#endif I would have moved all the detection code to patch 2/17 - including the static branch definition and enable below (except for vlen stuff) > > /** > * riscv_isa_extension_base() - Get base extension word > @@ -249,6 +257,16 @@ void __init riscv_fill_hwcap(void) > if (j >= 0) > static_branch_enable(&riscv_isa_ext_keys[j]); > } > + > +#ifdef CONFIG_VECTOR > + if (elf_hwcap & COMPAT_HWCAP_ISA_V) { > + static_branch_enable(&cpu_hwcap_vector); > + /* There are 32 vector registers with vlenb length. */ > + rvv_enable(); > + riscv_vsize = csr_read(CSR_VLENB) * 32; > + rvv_disable(); > + } > +#endif > } > > #ifdef CONFIG_RISCV_ALTERNATIVE > @@ -328,3 +346,4 @@ void __init_or_module riscv_cpufeature_patch_func(struct alt_entry *begin, > } > } > #endif > +} > diff --git a/arch/riscv/kernel/riscv_ksyms.c b/arch/riscv/kernel/riscv_ksyms.c > index 5ab1c7e1a6ed..3489d2a20ca3 100644 > --- a/arch/riscv/kernel/riscv_ksyms.c > +++ b/arch/riscv/kernel/riscv_ksyms.c > @@ -15,3 +15,9 @@ EXPORT_SYMBOL(memmove); > EXPORT_SYMBOL(__memset); > EXPORT_SYMBOL(__memcpy); > EXPORT_SYMBOL(__memmove); > + > +#ifdef CONFIG_VECTOR > +#include > +EXPORT_SYMBOL(rvv_enable); > +EXPORT_SYMBOL(rvv_disable); > +#endif > diff --git a/arch/riscv/kernel/vector.S b/arch/riscv/kernel/vector.S > new file mode 100644 > index 000000000000..9f7dc70c4443 > --- /dev/null > +++ b/arch/riscv/kernel/vector.S > @@ -0,0 +1,93 @@ > +/* SPDX-License-Identifier: GPL-2.0 */ > +/* > + * Copyright (C) 2012 Regents of the University of California > + * Copyright (C) 2017 SiFive > + * Copyright (C) 2019 Alibaba Group Holding Limited > + * > + * This program is free software; you can redistribute it and/or > + * modify it under the terms of the GNU General Public License > + * as published by the Free Software Foundation, version 2. > + * > + * This program is distributed in the hope that it will be useful, > + * but WITHOUT ANY WARRANTY; without even the implied warranty of > + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the > + * GNU General Public License for more details. > + */ > + > +#include > + > +#include > +#include > +#include > + > +#define vstatep a0 > +#define datap a1 > +#define x_vstart t0 > +#define x_vtype t1 > +#define x_vl t2 > +#define x_vcsr t3 > +#define incr t4 > +#define status t5 > + A few words here as to when is this save/restore done. Best to do this in the patch which actually uses this code. > +ENTRY(__vstate_save) > + li status, SR_VS > + csrs CSR_STATUS, status > + > + csrr x_vstart, CSR_VSTART > + csrr x_vtype, CSR_VTYPE > + csrr x_vl, CSR_VL > + csrr x_vcsr, CSR_VCSR > + vsetvli incr, x0, e8, m8, ta, ma > + vse8.v v0, (datap) > + add datap, datap, incr > + vse8.v v8, (datap) > + add datap, datap, incr > + vse8.v v16, (datap) > + add datap, datap, incr > + vse8.v v24, (datap) > + > + REG_S x_vstart, RISCV_V_STATE_VSTART(vstatep) > + REG_S x_vtype, RISCV_V_STATE_VTYPE(vstatep) > + REG_S x_vl, RISCV_V_STATE_VL(vstatep) > + REG_S x_vcsr, RISCV_V_STATE_VCSR(vstatep) > + > + csrc CSR_STATUS, status > + ret > +ENDPROC(__vstate_save) > + > +ENTRY(__vstate_restore) > + li status, SR_VS > + csrs CSR_STATUS, status > + > + vsetvli incr, x0, e8, m8, ta, ma > + vle8.v v0, (datap) > + add datap, datap, incr > + vle8.v v8, (datap) > + add datap, datap, incr > + vle8.v v16, (datap) > + add datap, datap, incr > + vle8.v v24, (datap) > + > + REG_L x_vstart, RISCV_V_STATE_VSTART(vstatep) > + REG_L x_vtype, RISCV_V_STATE_VTYPE(vstatep) > + REG_L x_vl, RISCV_V_STATE_VL(vstatep) > + REG_L x_vcsr, RISCV_V_STATE_VCSR(vstatep) > + vsetvl x0, x_vl, x_vtype > + csrw CSR_VSTART, x_vstart > + csrw CSR_VCSR, x_vcsr > + > + csrc CSR_STATUS, status > + ret > +ENDPROC(__vstate_restore) > + > +ENTRY(rvv_enable) > + li status, SR_VS > + csrs CSR_STATUS, status > + ret > +ENDPROC(rvv_enable) > + > +ENTRY(rvv_disable) > + li status, SR_VS > + csrc CSR_STATUS, status > + ret > +ENDPROC(rvv_disable)