Received: by 2002:a05:6a10:22f:0:0:0:0 with SMTP id 15csp904409pxk; Thu, 10 Sep 2020 01:28:08 -0700 (PDT) X-Google-Smtp-Source: ABdhPJyDXdzeHEU1NMhJlrsH9fKnXDAYKMKws++S+RGQdJnximGiLYKT2xe5iCEsOAeVz/gUeSwO X-Received: by 2002:a17:906:1ed4:: with SMTP id m20mr7840741ejj.460.1599726488684; Thu, 10 Sep 2020 01:28:08 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1599726488; cv=none; d=google.com; s=arc-20160816; b=GZ8/7lWTc8dt+35ZW7QV3LyITzpYgvAio3mJvaDRtyTH+1ZVKFvHW9SsUWbCn2sSsJ Nn5paSWXM4Qfgvdduy26wcqoH57GItemtc2A6fnjfAd0c2MmAN/o/cX6a9XZ593jal+Q F/hcSQXotMx+qGJ8ph6vSBjko4TWQOz43F9wnkldDh/9p+iUvPY2Tc7zv5bXzHDrdySv EXYKzobMEwEnr99WpfRXdB3dZoLcpBR5HpygmVLWdpVeS7nzwfealjFRCHS8UJ/JU7Ht HtfXPlr2GsQ2/+LBPLC8I/jhbJ01MywuB9ys5FnVV22QZYEhwJONHEcc9eChQXGn6m7S sWWg== 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:to:from :dkim-signature; bh=XVF1RkRlNyjr4ZwKxBdakcqACyTLVz5RhfVby+r/t60=; b=YxNgTG4vQ9OxTM4xoEFdMSWHmzEPZgGo/2yArfJHtxo7UYoBQ5I4zMtZPyKZWtrrwy kv+yPZOY+iaRcwsh9eMoLGgU6X+CLOiFLaUFIidfnGjH50rbaZmJiaG3dptDChqp9a2q hXzavad+t8Rnb7w0Udik5s1oTKDDaBJT+IIhBhmzivrmUHGc9TmXYg/dslci/TcYoqBf kneM0ZZ3DUEGhmOBttFgeHipKVjb/h5pjIqMtKi9M0fm1fjT1DiD+KYOvQm7TkJ6hzn1 81uPHdw9aJLdZ2bzteV+DoXSN91KDFQem02I/Fc1Efr8U++yKwx2QwjipeLNeO6oDFyJ jREA== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=OZZuvrCM; 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 k25si3189064ejq.407.2020.09.10.01.27.46; Thu, 10 Sep 2020 01:28:08 -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=OZZuvrCM; 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 S1728463AbgIJIYG (ORCPT + 99 others); Thu, 10 Sep 2020 04:24:06 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:53800 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1730131AbgIJINl (ORCPT ); Thu, 10 Sep 2020 04:13:41 -0400 Received: from mail-pl1-x641.google.com (mail-pl1-x641.google.com [IPv6:2607:f8b0:4864:20::641]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 414B1C0617A1 for ; Thu, 10 Sep 2020 01:13:17 -0700 (PDT) Received: by mail-pl1-x641.google.com with SMTP id d16so529724pll.13 for ; Thu, 10 Sep 2020 01:13:17 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; h=from:to:subject:date:message-id:in-reply-to:references:mime-version :content-transfer-encoding; bh=XVF1RkRlNyjr4ZwKxBdakcqACyTLVz5RhfVby+r/t60=; b=OZZuvrCM/fVMSzDsPqGkcs1Ug1kb60GjZWJgGPcxppiDKKwMnzcrRnUsA5dPYnUB/K B37Qj9Ch3z+WfZzhg8cj+xYFZVBy6HQrls549qeKzHvptK/I2tXv2z00p7wO6r8m1cau TUobCL4MFOFdgMajtXCVjPg5V/F3yGL3ePOTAINZtP/iymisM8ch9Mt3GFQNq9k13x9R nGtsL8NJSZiVy6k3FJjFx+EcqLodkh6hRxdtcyxDxdRq2KtS3gmNEQuYUH7/5Q49g7IQ 3wgiuAcDuA1+1iWh97dCClfXjK7MyE4UVu/lRwBBXUut/Vx3t7oXwO+VLOLCoN3TmJMj 8cjg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=XVF1RkRlNyjr4ZwKxBdakcqACyTLVz5RhfVby+r/t60=; b=mBcWRsFgqMYUuk7Y8Q3V3DYb35/spXOXtJyFwuZ8dYWq/di5OZij0B0mXKaHk35oqu Y2jotsM1Jo2a5hMV3Qy7O9vO4CQavnvmY4IT6JQU1HG34ShmtXfiDP/NyUIpncMtK2KV caRJmbFyGTT4lWapUQ2xYtyywwdwikLiSOPYwvG58P+6nvaGC2l3FPdUlgCugFqeRyW+ hS4A1winJdIFQLNx1tfuKEmRZZeYjEqOgzsmJZC5ppeZqvdGXZC4RWyOMLQ+egutHzJb rUh/RuCHPfJ1R9Re34/HN4wngmwFRq6fwh0KHjEM8sCT3VS/lo6y5lGyFvV0Wlr0rz0m Ps+Q== X-Gm-Message-State: AOAM530lQQtn04DTKMCt2LQD/gbwEdIt9f8ErB4MESbfgc+wg6FN9sW0 l7G1k9rA6DW6QYo2ZpZy3l0lzA== X-Received: by 2002:a17:902:59d8:b029:d0:89f1:9e2d with SMTP id d24-20020a17090259d8b02900d089f19e2dmr4668405plj.9.1599725596763; Thu, 10 Sep 2020 01:13:16 -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.13.15 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Thu, 10 Sep 2020 01:13:16 -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 Subject: [RFC PATCH v7 19/21] riscv: Fix an illegal instruction exception when accessing vlenb without enable vector first Date: Thu, 10 Sep 2020 16:12:14 +0800 Message-Id: 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 It triggered an illegal instruction exception when accessing vlenb CSR without enable vector first. To fix this issue, we should enable vector before using it and disable vector after using it. Signed-off-by: Greentime Hu --- arch/riscv/include/asm/vector.h | 2 ++ arch/riscv/kernel/cpufeature.c | 3 +++ arch/riscv/kernel/kernel_mode_vector.c | 6 ++++-- 3 files changed, 9 insertions(+), 2 deletions(-) diff --git a/arch/riscv/include/asm/vector.h b/arch/riscv/include/asm/vector.h index 3fc8d84e23c6..a99bbda7f4ba 100644 --- a/arch/riscv/include/asm/vector.h +++ b/arch/riscv/include/asm/vector.h @@ -10,6 +10,8 @@ #include +void rvv_enable(void); +void rvv_disable(void); void kernel_rvv_begin(void); void kernel_rvv_end(void); diff --git a/arch/riscv/kernel/cpufeature.c b/arch/riscv/kernel/cpufeature.c index 4d4f78f6a5db..817980d38603 100644 --- a/arch/riscv/kernel/cpufeature.c +++ b/arch/riscv/kernel/cpufeature.c @@ -22,6 +22,7 @@ static DECLARE_BITMAP(riscv_isa, RISCV_ISA_EXT_MAX) __read_mostly; bool has_fpu __read_mostly; #endif #ifdef CONFIG_VECTOR +#include bool has_vector __read_mostly; unsigned long riscv_vsize __read_mostly; #endif @@ -158,7 +159,9 @@ void riscv_fill_hwcap(void) if (elf_hwcap & COMPAT_HWCAP_ISA_V) { has_vector = true; /* There are 32 vector registers with vlenb length. */ + rvv_enable(); riscv_vsize = csr_read(CSR_VLENB) * 32; + rvv_disable(); } #endif } diff --git a/arch/riscv/kernel/kernel_mode_vector.c b/arch/riscv/kernel/kernel_mode_vector.c index b84618630edf..0d990bd8b8dd 100644 --- a/arch/riscv/kernel/kernel_mode_vector.c +++ b/arch/riscv/kernel/kernel_mode_vector.c @@ -71,15 +71,17 @@ static void put_cpu_vector_context(void) preempt_enable(); } -static void rvv_enable(void) +void rvv_enable(void) { csr_set(CSR_STATUS, SR_VS); } +EXPORT_SYMBOL(rvv_enable); -static void rvv_disable(void) +void rvv_disable(void) { csr_clear(CSR_STATUS, SR_VS); } +EXPORT_SYMBOL(rvv_disable); static void vector_flush_cpu_state(void) { -- 2.28.0