Received: by 2002:a05:6359:c8b:b0:c7:702f:21d4 with SMTP id go11csp6009752rwb; Wed, 21 Sep 2022 16:09:11 -0700 (PDT) X-Google-Smtp-Source: AMsMyM4hjNOx7XfeELuWZnKWFqMHCdCKZbEsj/w43LH29IfA0uv8zkcu/Zp9L230xqJXpyhzKFIE X-Received: by 2002:a17:907:7d9e:b0:771:db66:7b7c with SMTP id oz30-20020a1709077d9e00b00771db667b7cmr469073ejc.393.1663801751279; Wed, 21 Sep 2022 16:09:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1663801751; cv=none; d=google.com; s=arc-20160816; b=nWowu30KoQe07CG5BMlRtS5jKQy6s/xBxFyZ34M+2ScAp37hzGLOUQ+QYgk6RRVeae 8+KnIw5sDxB9FxJHtE0srbPv4bR8ppk5uqDJfjuKgdoJN95nxAEVfRu8doUWyP8iOlh1 IkmmVYbSJ64NH3oI5bKZFH/P7wHuLYb7Wx099V2oFbR4pc78CJwOtb0RGuB3EO957Qd/ yolgb7PVs9P+Mz63jUPJD+OGngWbQ3oOZF+wfx4/sNlZd3kyAASwV7jOr4w9ymDgZzkl aWzi+tsPE/ebmETuPWzNuw7sIm0zg/fZW7677PrdMdQ81nL2QOsj35g9wAhLuOh64z3X eFcw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:to:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:cc:from :dkim-signature; bh=LT61xLA3xO8Cm0mngS+B9eObitluLVCYOP6BvnQtjLU=; b=sLYboTCd92HUi+wkpfzpxtv2AuFHWJsPqqd7GGK5axUCrbQbk7jMoSQ0g4hZahXRv3 NaeirYqBe5cqwoiAqnjky5pcPqHIGo7Fuw/hVySacypobntHvV7/vCLB9dOY+EMgBch9 17fsQhmMVQnuh5nFIa0bp4TzZ7hiT5AVXtQtxE4QCxC2QJpfp5+M7QioHd1R/gafDd0Q sOiWWuE8eapsnEBUQqN939fi0V+mQguLXnUVDMPqBN377KP7NE+0/97to53D0PiWi+m4 yCUxPw6Ij9thTzVPMCwuPcabyRK3kJeceHqaWeFPq7Kcoxps1Actfcpb8SSPSIAM+2Mb /+JQ== ARC-Authentication-Results: i=1; mx.google.com; dkim=fail header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=KTbyz47q; 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 Return-Path: Received: from out1.vger.email (out1.vger.email. [2620:137:e000::1:20]) by mx.google.com with ESMTP id ds14-20020a170907724e00b0077be1301563si2293655ejc.196.2022.09.21.16.08.44; Wed, 21 Sep 2022 16:09:11 -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=fail header.i=@rivosinc-com.20210112.gappssmtp.com header.s=20210112 header.b=KTbyz47q; 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 Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230301AbiIUVsm (ORCPT + 99 others); Wed, 21 Sep 2022 17:48:42 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:52110 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230346AbiIUVsk (ORCPT ); Wed, 21 Sep 2022 17:48:40 -0400 Received: from mail-pj1-x102c.google.com (mail-pj1-x102c.google.com [IPv6:2607:f8b0:4864:20::102c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 4E702857FB for ; Wed, 21 Sep 2022 14:48:39 -0700 (PDT) Received: by mail-pj1-x102c.google.com with SMTP id s90-20020a17090a2f6300b00203a685a1aaso171168pjd.1 for ; Wed, 21 Sep 2022 14:48:39 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:from:to:cc:subject:date; bh=LT61xLA3xO8Cm0mngS+B9eObitluLVCYOP6BvnQtjLU=; b=KTbyz47q38rOvNH4MaSFOrps1Y9zCXQ6Q5/53AoIJm1skkxgugSIuwlert/lAleh50 KvK8X42g6WNWey323t+KIBlDGBSiX+NAfIP5aAUfONFStURjNCuR33L1g1krNqS8f9KO IJp19kSHkgX78HqozbEi+07FKRDe3HS0DEb6wmgKKIJT5hQrnS34T7kP7VwkOZNUq3wg NvsuP3vWYb4dbYHcCDkRQ/hZG87FqeSM3JfnpkntZ5bbBEKDYYEqp+9tvRUWY0tQQ7qT UtgVhD8d2FYBmISbFP22uUgEi2cTPvHDeSXzFyQpKxIcvqP0GYDLJWQJrK1/1DPv+tHa WrTQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=content-transfer-encoding:mime-version:references:in-reply-to :message-id:date:subject:cc:to:from:x-gm-message-state:from:to:cc :subject:date; bh=LT61xLA3xO8Cm0mngS+B9eObitluLVCYOP6BvnQtjLU=; b=FHlJ+WnleLY0gMB9C70gmBBaNt3HKdfcsKSMwQ9RyKAz8a+HRZ2uLrN9wXFgDPlCVN COsIZemtk1xMdscF2HAjSbC/xxU2fzhRtgcmwVk5YCYaGdRNnHjN3mk58FrrBoBaVnpM 4+XFff/1JnV+3G/kygUaY/U0/iEHY42dllfNeQ4KZKybn2CFprjqN5cR8EAmYhJpgt0K uuh4q04qu8YBXnq4KO534hLBItttBz2Xvy41lfaFxS4i5y7zAQvjm3tQfcKSEINq9eHx hAF8oA8C1wefqaJMBL5Vi+e8fng9iX7dP5Ei/1g2h42oz+SgwZCQ1IU9y3oAAC5AtNpm SqYw== X-Gm-Message-State: ACrzQf0uBhwfgVzrw4kQZrdnk5AF6VQk8Qm0y/z3e4InHeBeda3sJaGA rS+Fyxy30J4F5YZ+fUmTmnfSfA== X-Received: by 2002:a17:902:e383:b0:176:9ee2:e099 with SMTP id g3-20020a170902e38300b001769ee2e099mr270156ple.44.1663796918852; Wed, 21 Sep 2022 14:48:38 -0700 (PDT) Received: from stillson.ba.rivosinc.com ([66.220.2.162]) by smtp.gmail.com with ESMTPSA id k7-20020aa79727000000b005484d133127sm2634536pfg.129.2022.09.21.14.48.36 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 21 Sep 2022 14:48:38 -0700 (PDT) From: Chris Stillson Cc: 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 , Guo Ren , Chris Stillson , Mayuresh Chitale , Paolo Bonzini , Alexandre Ghiti , Qinglin Pan , Arnd Bergmann , Heiko Stuebner , Jisheng Zhang , Dao Lu , "Peter Zijlstra (Intel)" , Sunil V L , Ruinland Tsai , Li Zhengyu , Alexander Graf , Ard Biesheuvel , Tsukasa OI , Yury Norov , Nicolas Saenz Julienne , Mark Rutland , Frederic Weisbecker , Changbin Du , Vitaly Wool , Myrtle Shah , Catalin Marinas , Will Deacon , Mark Brown , Alexey Dobriyan , Huacai Chen , Janosch Frank , Christian Brauner , Peter Collingbourne , Eugene Syromiatnikov , Colin Cross , Andrew Morton , Barret Rhoden , Suren Baghdasaryan , Davidlohr Bueso , linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, linux-mm@kvack.org, kvm@vger.kernel.org, kvm-riscv@lists.infradead.org Subject: [PATCH v12 06/17] riscv: Reset vector register Date: Wed, 21 Sep 2022 14:43:48 -0700 Message-Id: <20220921214439.1491510-6-stillson@rivosinc.com> X-Mailer: git-send-email 2.25.1 In-Reply-To: <20220921214439.1491510-1-stillson@rivosinc.com> References: <20220921214439.1491510-1-stillson@rivosinc.com> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Spam-Status: No, score=-1.9 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,RCVD_IN_DNSWL_NONE,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 To: unlisted-recipients:; (no To-header on input) Precedence: bulk List-ID: X-Mailing-List: linux-kernel@vger.kernel.org From: Guo Ren Reset vector registers at boot-time and disable vector instructions execution for kernel mode. Signed-off-by: Guo Ren Co-developed-by: Vincent Chen Signed-off-by: Vincent Chen Co-developed-by: Han-Kuan Chen Signed-off-by: Han-Kuan Chen Co-developed-by: Greentime Hu Signed-off-by: Greentime Hu Reviewed-by: Palmer Dabbelt --- arch/riscv/kernel/entry.S | 6 +++--- arch/riscv/kernel/head.S | 35 +++++++++++++++++++++++++++++------ 2 files changed, 32 insertions(+), 9 deletions(-) diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index b9eda3fcbd6d..1e9987376591 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -77,10 +77,10 @@ _save_context: * Disable user-mode memory access as it should only be set in the * actual user copy routines. * - * 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 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 #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 */ +#endif /* CONFIG_VECTOR */ + .Lreset_regs_done: ret END(reset_regs) -- 2.25.1