Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp900390pxk; Thu, 10 Sep 2020 01:19:09 -0700 (PDT) X-Google-Smtp-Source: ABdhPJw/A6UVkIRSgCuEoNbQ7n/kzHS1zZkqBsx7AcJY+aRf4iUriAJGOpNOxibrDcBrL+3ZsCc3 X-Received: by 2002:a17:906:cec9:: with SMTP id si9mr7411649ejb.351.1599725949075; Thu, 10 Sep 2020 01:19:09 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599725949; cv=none; d=google.com; s=arc-20160816; b=WqzbWP90nG7zAMYaxsOYGU+aTfhfoatGOsq+12nFiEVhDtZqnAvEJVmJjQ0XAfnwzL cOT1nyXdh0ojeJcOdqsk6UjI7n5aJvPJ0ABsdsUienQkBnEuk5VF8bM5y03gB9cqKf/3 93oqiT6IJ62LT6R0+eI5TzWiSAal56fOgm9/r7tPHFYyI+xoAcBYfgtZRa06VQKkYQ8D T6HaBZGBD/u+osYyVw8VIbM3JR+0MvOZ8t/izkfKZHVhyuXhq0eqS1sXIsvyUe3+4Jdf YY/PAhi3vWOn0EYDeLTNjgj2ozjMqEO6XOi8yqjO0E25rW0W0MNT3mwOTC9UdHquagB7 iyDw== 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 :dkim-signature; bh=ommHQQSpigOoxveeOFgXjiVdJvwUb8j2DzRPHrvB8ew=; b=uwnLhSE7/lvem+D2Is2omccqLPXdJ18LcOLGuGOYvChPKrhpYcH2t1DMqwe2PT24/k dqgbPnJ9QjTdTBSaEE875tNNF5qDoNZ04Oq76NKeveeNJR2xNTv9sscmdfllH0Vcd42m 7ha6pnRbaTLBu5Vl/qq09IG4aMbcdFEZuZS3gPiUF9OjDgkcuCMt/B8KIy4x93MAdDHr w+YHFE3Tr9xg1boFS99xSVhqTMp77RAWdVAfLBF71S+ZkX+AdLdrXapLL3gCppptDAOW lrv09YJ+0hv1YFCL0HjyuiG5OIZPexaqdmyLUpcP7U3ZH0xgqenqqVRp8vzihg8vn1Dt r7jA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=Q2cGez+F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Return-Path: Received: from vger.kernel.org (vger.kernel.org. [23.128.96.18]) by mx.google.com with ESMTP id g11si2840716eds.232.2020.09.10.01.18.46; Thu, 10 Sep 2020 01:19:09 -0700 (PDT) Received-SPF: pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) client-ip=23.128.96.18; Authentication-Results: mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=Q2cGez+F; spf=pass (google.com: domain of linux-kernel-owner@vger.kernel.org designates 23.128.96.18 as permitted sender) smtp.mailfrom=linux-kernel-owner@vger.kernel.org Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S1730214AbgIJIRy (ORCPT + 99 others); Thu, 10 Sep 2020 04:17:54 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53656 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1729663AbgIJIMw (ORCPT ); Thu, 10 Sep 2020 04:12:52 -0400 Received: from mail-pf1-x443.google.com (mail-pf1-x443.google.com [IPv6:2607:f8b0:4864:20::443]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id DDCFFC061756 for ; Thu, 10 Sep 2020 01:12:51 -0700 (PDT) Received: by mail-pf1-x443.google.com with SMTP id k15so4165537pfc.12 for ; Thu, 10 Sep 2020 01:12:51 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:cc:subject:date:message-id:in-reply-to:references :mime-version:content-transfer-encoding; bh=ommHQQSpigOoxveeOFgXjiVdJvwUb8j2DzRPHrvB8ew=; b=Q2cGez+F8URgAoZvPAYByAl6wQOxX86fqXQguCLGEvBvEVALos9gy+uGgwCfIaqzx4 tQAN+B8kOPNupoqb1AZETPXjyLVaqWO0hRhl3MbUE2G4YQstbdgBJvkVE3jMsPzY9JGq duU4NTbnVx7Bp3jjv+xrBpjQXRX7KXD7xZlO1c9y5iLb/siA0xBPxtbN8vIvYBmqI0bW 47Swj8CvaqU/+YSM++ibx1DXz4ja3Gotg2Q7Gdcq1b+giT78Y60o6Ca8ZWg6RCUS4VX9 IyUfwSLcj0qa1AAxEK7saXRh6+Yw+v5qLo/zkdyEOxLScRUgFTr+PwnfhaBRt/Z3hasj Y9Jw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:cc:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ommHQQSpigOoxveeOFgXjiVdJvwUb8j2DzRPHrvB8ew=; b=Wehm6x0wTyIQ6U+iSYDz7WyA/0A7A871dtMRUZ6ueD+2oRWVcV3PuBOxTQZ387yK9c SjL4D6BzYWGSUyedFdMy2L4ewRXRA6EiDYnSuK8HW/f/nksLFGzIODfEbA7hzf6U62yz uITKsUFOEYL+VE59DyPK0IFipPlN+M4Ztt2fKpqxKvRCsLdXoCxTxQooi3PsWpF2HWS8 Et71+YQ31P7NPEgYZBy11HfkN+kbQI92RPowXn6SWLsHp4rBuv33Lqrn2IaNlXc/ljG2 IxemeevjQ2Qo8OCsKE9uSkb7xmrXZ5maFhL7S3WpcDyLtE+GZJFmZ2OYnmpi9IgkzrCs 5jwg== X-Gm-Message-State: AOAM533ak0R/YFId2ag0U0dmN4yhNTjBW2yUgd0ZOx9b+Ysk6PxSIubg H3hgzOpYjzh2/K9Wh9tZRtjRBA== X-Received: by 2002:a63:fd51:: with SMTP id m17mr3785010pgj.210.1599725571382; Thu, 10 Sep 2020 01:12:51 -0700 (PDT) Received: from hsinchu02.internal.sifive.com (114-34-229-221.HINET-IP.hinet.net. [114.34.229.221]) by smtp.gmail.com with ESMTPSA id e1sm2196056pfl.162.2020.09.10.01.12.49 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 01:12:50 -0700 (PDT) From: Greentime Hu To: greentime.hu@sifive.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, aou@eecs.berkeley.edu, palmer@dabbelt.com, paul.walmsley@sifive.com Cc: Guo Ren Subject: [RFC PATCH v7 07/21] riscv: Reset vector register Date: Thu, 10 Sep 2020 16:12:02 +0800 Message-Id: <9ea7cdc5f290d33f52643ec00830362723b71ec4.1599719352.git.greentime.hu@sifive.com> X-Mailer: git-send-email 2.28.0 In-Reply-To: References: 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 From: Guo Ren Reset vector registers at boot-time and disable vector instructions execution for kernel mode. [greentime.hu@sifive.com: add comments] Signed-off-by: Greentime Hu Signed-off-by: Guo Ren --- arch/riscv/kernel/entry.S | 6 ++--- arch/riscv/kernel/head.S | 49 +++++++++++++++++++++++++++++++++++++-- 2 files changed, 50 insertions(+), 5 deletions(-) diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index 524d918f3601..c905efb6c998 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -67,10 +67,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 0a4e81b8dc79..e97c7915ae27 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -204,10 +204,10 @@ pmp_done: .option pop /* - * Disable FPU to detect illegal usage of + * Disable FPU & VECTOR to detect illegal usage of * floating point in kernel space */ - li t0, SR_FS + li t0, SR_FS | SR_VS csrc CSR_STATUS, t0 #ifdef CONFIG_SMP @@ -365,6 +365,51 @@ 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 >> 16) + slli t1, t1, 16 + and t0, t0, t1 + beqz t0, .Lreset_regs_done + + li t1, SR_VS + csrs CSR_STATUS, t1 + vmv.v.i v0, 0 + vmv.v.i v1, 0 + vmv.v.i v2, 0 + vmv.v.i v3, 0 + vmv.v.i v4, 0 + vmv.v.i v5, 0 + vmv.v.i v6, 0 + vmv.v.i v7, 0 + vmv.v.i v8, 0 + vmv.v.i v9, 0 + vmv.v.i v10, 0 + vmv.v.i v11, 0 + vmv.v.i v12, 0 + vmv.v.i v13, 0 + vmv.v.i v14, 0 + vmv.v.i v15, 0 + vmv.v.i v16, 0 + vmv.v.i v17, 0 + vmv.v.i v18, 0 + vmv.v.i v19, 0 + vmv.v.i v20, 0 + vmv.v.i v21, 0 + vmv.v.i v22, 0 + vmv.v.i v23, 0 + vmv.v.i v24, 0 + vmv.v.i v25, 0 + vmv.v.i v26, 0 + vmv.v.i v27, 0 + vmv.v.i v28, 0 + vmv.v.i v29, 0 + vmv.v.i v30, 0 + vmv.v.i v31, 0 + /* note that the caller must clear SR_VS */ +#endif /* CONFIG_VECTOR */ + .Lreset_regs_done: ret END(reset_regs) -- 2.28.0