Received: by 2002:a05:6358:16cd:b0:dc:6189:e246 with SMTP id r13csp425704rwl; Fri, 4 Nov 2022 02:00:37 -0700 (PDT) X-Google-Smtp-Source: AMsMyM6lTfFQ3209o3zeTwKl7KHyzYvLputcyHW+WpcYdA6mWdTA6Ll0hYLCv9LW/GRrU6Hrd1BU X-Received: by 2002:a17:90b:1806:b0:213:bf67:4d4f with SMTP id lw6-20020a17090b180600b00213bf674d4fmr32605245pjb.30.1667552437019; Fri, 04 Nov 2022 02:00:37 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1667552437; cv=none; d=google.com; s=arc-20160816; b=BXxXPZafvkwQKlAzLQlQJzPgr41CUHtvalXpfCHxPHpvJlPaTnF88SU5acyCfXsZaF yqSeLhHpbnLjX84k4+1w26JUt2m2rGbOeNjAv24SyVZIBxv2jnfzLQVbRiqmR1VT9lr4 mB1omiBr9/G729e+nNePBBrx9NRc0mo1w4kfcDBbJGFTVo9ZoX7Os1Lg+lPoATJFkTYb Gztkr+5pXmvF5afyM1sd0QpvgL7Pl6f/jZj66OwGz6NSol1xaet8TP/0SZTSzepghCLL 86l35lPAdFVtUCwLvk/FqV3T5vxPdKxRbai/S7OD0BTH6iG70FlnkyEofkSsGyX9P+wK E2TA== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:cc:to:subject:message-id:date:from:in-reply-to :references:mime-version:dkim-signature; bh=SiIy9Ysvo3ISuTrtg4Q7Wzizl7xZ7egYFaRsM7DsSAc=; b=URS0uVVZWW9lyBNZp/tg39tOxiZSLhRatz51ZePl4EZ1gQZ2DmaO4KRxnqBX2yq3LW cgDcVUdp1i4rXkSv5Bya+PRvNUc0Ml1N/DTo/7w88wtqInN1mLsIB6y8CgVSleHY5FPm qqNJVCQcUX63kJgLFAFiu5SKx5A7QK1r2JtxfmJssKTy8PBmaaefdixSkIsxayuigY43 dRbsfVNkPz9tMFLrSzGm3/T34YBiE+E2NcPq+6WXKS0mP5VObNcwU5B04XY8CJexmxaG zogudOFLZEGc5vvpafecmaWz9KpvJy1S0MLZBjDDF+TK01aL+uSOP/rgU/imqVNoXI7X uzHA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bh2jFjjE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id d18-20020a170902e15200b00182b78df2f8si2976832pla.495.2022.11.04.02.00.24; Fri, 04 Nov 2022 02:00:37 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) client-ip=2620:137:e000::1:20; Authentication-Results: mx.google.com; dkim=pass header.i=@kernel.org header.s=k20201202 header.b=bh2jFjjE; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 2620:137:e000::1:20 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org; dmarc=pass (p=NONE sp=NONE dis=NONE) header.from=kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230199AbiKDIqF (ORCPT + 97 others); Fri, 4 Nov 2022 04:46:05 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:57104 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S229481AbiKDIqC (ORCPT ); Fri, 4 Nov 2022 04:46:02 -0400 Received: from ams.source.kernel.org (ams.source.kernel.org [145.40.68.75]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id D752CD2D1 for ; Fri, 4 Nov 2022 01:46:00 -0700 (PDT) Received: from smtp.kernel.org (relay.kernel.org [52.25.139.140]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ams.source.kernel.org (Postfix) with ESMTPS id 7E310B82C40 for ; Fri, 4 Nov 2022 08:45:59 +0000 (UTC) Received: by smtp.kernel.org (Postfix) with ESMTPSA id 2443BC433C1 for ; Fri, 4 Nov 2022 08:45:58 +0000 (UTC) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/simple; d=kernel.org; s=k20201202; t=1667551558; bh=ByyutI2vBA3QhVIGyC66aA8zyhVYs5f2konmfwSQPnc=; h=References:In-Reply-To:From:Date:Subject:To:Cc:From; b=bh2jFjjEHZPtABoc/F6qzcbKAtleQlQvRlhOGeRNTbYwEmG2rOHmRD6uBT0RttSI6 Z9TCeCXZO6vS83C3Q9D2Olc1eEnAKxDRkZoMHkR39LMa6guFz7U/KWfFbcDVqfPyM6 KwPlws3b7XQZqQgnrBYqXX1nCsqbkaez/9+CT5Yob30/oKWezytIV74nGKmtjkupYy B2fZTcZsH432eIxxo6Iv87WgGcudXhW/fEUbRxucxmbHokk0NAYfpovZtCRIZQyCLL AMwbBOh+OgvCyoBaIuVd9kUtzjNHQbWUQkRKJnU2rt4umhrfInZ1yWyYXIKvsv5ND3 w5rSaSRtGFjKg== Received: by mail-oi1-f180.google.com with SMTP id t62so4489373oib.12 for ; Fri, 04 Nov 2022 01:45:58 -0700 (PDT) X-Gm-Message-State: ACrzQf3hP5f35yhu2A6R7ecpFeGoXQoCf/Rsv3fhsFCMnWBQE9wfMJN8 mNUho5+dgyQRLIRnooVBile1QskcdSpNDaX4QR0= X-Received: by 2002:a05:6808:f0e:b0:359:b055:32ea with SMTP id m14-20020a0568080f0e00b00359b05532eamr26767203oiw.112.1667551557278; Fri, 04 Nov 2022 01:45:57 -0700 (PDT) MIME-Version: 1.0 References: <20220921214439.1491510-1-stillson@rivosinc.com> <20220921214439.1491510-6-stillson@rivosinc.com> <1c74ac94-50db-ceb3-234d-f8f227de8f6e@linux.dev> In-Reply-To: <1c74ac94-50db-ceb3-234d-f8f227de8f6e@linux.dev> From: Guo Ren Date: Fri, 4 Nov 2022 16:45:44 +0800 X-Gmail-Original-Message-ID: Message-ID: Subject: Re: [PATCH v12 06/17] riscv: Reset vector register To: Vineet Gupta Cc: Chris Stillson , Guo Ren , Vincent Chen , Han-Kuan Chen , Greentime Hu , Palmer Dabbelt , Paul Walmsley , Palmer Dabbelt , Albert Ou , Eric Biederman , Kees Cook , Anup Patel , Atish Patra , Oleg Nesterov , Heinrich Schuchardt , Mayuresh Chitale , Paolo Bonzini , linux-riscv , lkml , Andy Chiu Content-Type: text/plain; charset="UTF-8" X-Spam-Status: No, score=-8.1 required=5.0 tests=BAYES_00,DKIMWL_WL_HIGH, DKIM_SIGNED,DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,RCVD_IN_DNSWL_HI, SPF_HELO_NONE,SPF_PASS autolearn=ham autolearn_force=no version=3.4.6 X-Spam-Checker-Version: SpamAssassin 3.4.6 (2021-04-09) on lindbergh.monkeyblade.net Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org On Fri, Nov 4, 2022 at 1:01 PM Vineet Gupta wrote: > > On 9/21/22 14:43, Chris Stillson wrote: > > From: Guo Ren > > > > Reset vector registers at boot-time and disable vector instructions > > execution for kernel mode. > > Perhaps bike-shedding, but "Reset" has a different connotation in > kernel, this is clear registers IMO. And "Reset Vector ..." sounds > totally different at first glance. Agree, "Clear vector registers" is okay. > > > > - * Disable the FPU to detect illegal usage of floating point in kernel > > - * space. > > + * Disable the FPU/Vector to detect illegal usage of floating point > > + * or vector in kernel space. > > */ > > - li t0, SR_SUM | SR_FS > > + li t0, SR_SUM | SR_FS | SR_VS > > Is VS writable in implementations not implementing V hardware. > > Priv spec seems to be confusing. It states > > "The FS[1:0] and VS[1:0] WARL fields..." > > Above implies it can be written always but will read legal values only. > But then this follows. > > "If neither the v registers nor S-mode is implemented, then VS > is read-only zero. If S-mode is implemented but the v registers > are not, VS may optionally be read-only zero" > > What does optionally mean for software ? The read-only zero bit is safe for writing 1, but the result is still zero. So let's keep it for easier coding. > > > > > REG_L s0, TASK_TI_USER_SP(tp) > > csrrc s1, CSR_STATUS, t0 > > diff --git a/arch/riscv/kernel/head.S b/arch/riscv/kernel/head.S > > index b865046e4dbb..2c81ca42ec4e 100644 > > --- a/arch/riscv/kernel/head.S > > +++ b/arch/riscv/kernel/head.S > > @@ -140,10 +140,10 @@ secondary_start_sbi: > > .option pop > > > > /* > > - * Disable FPU to detect illegal usage of > > - * floating point in kernel space > > + * Disable FPU & VECTOR to detect illegal usage of > > + * floating point or vector in kernel space > > */ > > - li t0, SR_FS > > + li t0, SR_FS | SR_VS > > csrc CSR_STATUS, t0 > > > > /* Set trap vector to spin forever to help debug */ > > @@ -234,10 +234,10 @@ pmp_done: > > .option pop > > > > /* > > - * Disable FPU to detect illegal usage of > > - * floating point in kernel space > > + * Disable FPU & VECTOR to detect illegal usage of > > + * floating point or vector in kernel space > > */ > > - li t0, SR_FS > > + li t0, SR_FS | SR_VS > > csrc CSR_STATUS, t0 > > Third instance of duplicated SR_FS | SR_VS. Better to add a helper > SR_FS_VS or some such macro. Good point. But we could move it to another patch and define a new SR_AXS for all. #define SR_AXS (SR_FS | SR_VS | SR_XS) > > > > > #ifdef CONFIG_RISCV_BOOT_SPINWAIT > > @@ -431,6 +431,29 @@ ENTRY(reset_regs) > > csrw fcsr, 0 > > /* note that the caller must clear SR_FS */ > > #endif /* CONFIG_FPU */ > > + > > +#ifdef CONFIG_VECTOR > > + csrr t0, CSR_MISA > > + li t1, COMPAT_HWCAP_ISA_V > > + and t0, t0, t1 > > + beqz t0, .Lreset_regs_done > > + > > + /* > > + * Clear vector registers and reset vcsr > > + * VLMAX has a defined value, VLEN is a constant, > > + * and this form of vsetvli is defined to set vl to VLMAX. > > + */ > > + li t1, SR_VS > > + csrs CSR_STATUS, t1 > > + csrs CSR_VCSR, x0 > > + vsetvli t1, x0, e8, m8, ta, ma > > + vmv.v.i v0, 0 > > + vmv.v.i v8, 0 > > + vmv.v.i v16, 0 > > + vmv.v.i v24, 0 > > + /* note that the caller must clear SR_VS */ > > Is that actually happening ? Yes, It's the same as FPU, see head.S _start_kernel: ENTRY(_start_kernel) .. /* Reset all registers except ra, a0, a1 */ call reset_regs ... > > -- Best Regards Guo Ren