Received: by 2002:a05:6a10:eb17:0:0:0:0 with SMTP id hx23csp775198pxb; Wed, 8 Sep 2021 12:03:11 -0700 (PDT) X-Google-Smtp-Source: ABdhPJx7rbK8fkigKrfSA/vIXCdLCPLK1KUTFBYvFscX4O11BtPNUpN2H7NtBEVZr3yZmrUjCfVY X-Received: by 2002:a05:6638:348e:: with SMTP id t14mr5441090jal.66.1631127791073; Wed, 08 Sep 2021 12:03:11 -0700 (PDT) ARC-Seal: i=1; a=rsa-sha256; t=1631127791; cv=none; d=google.com; s=arc-20160816; b=JV3vumP8xFXAYWB7OhQNqMYtnb81DMGpUK+ZGm4rcZyJ95X3TBfDZzlTia9bvpEtTK oaU84mL1y66cOQcy0VT2DSkPUtFMr1Q6Fj2Kts5qfww6pqabA0xYE9XoZqbuq0Euqiuu PrehHy3V5yvCIgSv4auQResl4/e0WAi3NGCQ3V1bdE/nqoAKlOOUT37eo+b3iMn7/+c1 q+7ts70caEoYZNDQz3xXsV5HXlXCqZHVM06LM7if2jArAJXfRFLCymHquUHji7X9jsjb m4PSrcIwXFKyi8viQwfs7i1s0aF8F68J4LiWmyPPILz6JBmnjVTxTUeXsHGZH902QTob dALw== ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=google.com; s=arc-20160816; h=list-id:precedence:content-transfer-encoding:mime-version :references:in-reply-to:message-id:date:subject:to:from :dkim-signature; bh=ki+aQge6R1sXYo05KVRlyGbundfKO7O/dFJoVBYav6Q=; b=icKkUn7M8He8Bi/LMULIs7QCqodt3JaRIJd9nj0sUchG0JGKv23q4WZEr/KAIQL78l ExFYh2YKLlZcoiL/nDLBKLoVPWB+a0j3GeNSFa1xR3ZlQWh6NDZXYHUs9bv/UGV10J8s RIoc0VxEjk+4sBIBZaLRQSffetmZT+u0nW6tvlxlgInGFzY8yjKY1/Q1Q/4/PM2tHiNR 3r98WIxIG0h7J8OSsdr9EyadGB/1xOmIfFz/jYoKzNrg95haz3f/b7Q7BWMA5r/PcTKl mGs0TIMRAAcZhyT/oYoQ4R9wT308K5Hmm32DK5tq1r9JFyEt1geAo7Fh4P6C9eeKDEa1 R2Ng== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b=Oq1gZ4+w; 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 f10si2709624ile.158.2021.09.08.12.02.54; Wed, 08 Sep 2021 12:03:11 -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=Oq1gZ4+w; 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 S1352616AbhIHRrv (ORCPT + 99 others); Wed, 8 Sep 2021 13:47:51 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:48568 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S1352618AbhIHRrR (ORCPT ); Wed, 8 Sep 2021 13:47:17 -0400 Received: from mail-pg1-x534.google.com (mail-pg1-x534.google.com [IPv6:2607:f8b0:4864:20::534]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 78D7DC061796 for ; Wed, 8 Sep 2021 10:46:04 -0700 (PDT) Received: by mail-pg1-x534.google.com with SMTP id w8so3407549pgf.5 for ; Wed, 08 Sep 2021 10:46:04 -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=ki+aQge6R1sXYo05KVRlyGbundfKO7O/dFJoVBYav6Q=; b=Oq1gZ4+wVC97YoorR2afif9hfeSg7/m0u23F1ahqNEGXQCUohIuVLg8xKX3KH+/tlQ ivqLBG0XyEMm1tlNeWm6yD7jSj0PUW0WcPnYGejMluZiKd6JA7y7jNLIyqpyrUSts8py KPCq+JAg30N7RFBp9Hci0P1Heu+oVKursFUdZpcRcQ709jmZQoNHXhO51NfEO7rymSCJ P8XtVa63FaqxQWqoVN4Z/YmAkakDZX6itlvumnmskroOlWG0+0XVMWT4Df4NefypKI4g EmDVoPdqHaz68CuhTKkuHow89vBpn1MP66rttvAcc2g0Ia93gSTaa9mOSVYDmEmF4HkJ oBuA== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:subject:date:message-id:in-reply-to :references:mime-version:content-transfer-encoding; bh=ki+aQge6R1sXYo05KVRlyGbundfKO7O/dFJoVBYav6Q=; b=zUrX0yMk4UBwmAcvmhRKANCkSBaN0DwP9LwoEd/Fo3PR64FzRWKWLwCe4QQ/ToYfKy 3u+y/7Yguo3CpBOJriOVNPE0v33/Z0NvE9lh3tWbrEUdw3R8No3wKFAaQ+BQJ1kiXOPu 5q9B5gTbjd9UoOuC2xvs+gsWfLscPzu0tTmrUS2VDQm3zQLPJ9+6mvqs3Vh6srlrUiUK iTjpW8naQvHKuj80kfraIiDcY14IP+YixQQi2RgpXLYQ1raSIoJoLZXT62chdSTFIJx1 K+P0x4iqyjb3ug743Gc351lCPjYFZC53ElF73wEg+GFUVa+96gMeWgjlwWVuWcAqJPNc iXYw== X-Gm-Message-State: AOAM533vb02/dPveYYkvYAxeJUsmB1zf6tFwifGEZ3KjM7Hgum+EnHyj 8kbpTAOqKuKSgZe1pHhqR3NSWQ== X-Received: by 2002:a62:4e4c:0:b0:405:4360:33f8 with SMTP id c73-20020a624e4c000000b00405436033f8mr4939771pfb.56.1631123164061; Wed, 08 Sep 2021 10:46:04 -0700 (PDT) Received: from hsinchu16.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id b5sm3108466pfr.26.2021.09.08.10.46.02 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Wed, 08 Sep 2021 10:46:03 -0700 (PDT) From: Greentime Hu To: linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, aou@eecs.berkeley.edu, palmer@dabbelt.com, paul.walmsley@sifive.com, vincent.chen@sifive.com Subject: [RFC PATCH v8 18/21] riscv: Fix an illegal instruction exception when accessing vlenb without enable vector first Date: Thu, 9 Sep 2021 01:45:30 +0800 Message-Id: <28a21e13ee57b493c48f70cb27e7a527b21e3b96.1631121222.git.greentime.hu@sifive.com> X-Mailer: git-send-email 2.31.1 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: 8bit 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. Co-developed-by: Vincent Chen Signed-off-by: Vincent Chen 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 5d7f14453f68..ca063c8f47f2 100644 --- a/arch/riscv/include/asm/vector.h +++ b/arch/riscv/include/asm/vector.h @@ -8,6 +8,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 7265d947d981..af984f875f60 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; __ro_after_init DEFINE_STATIC_KEY_FALSE(cpu_hwcap_fpu); #endif #ifdef CONFIG_VECTOR +#include bool has_vector __read_mostly; unsigned long riscv_vsize __read_mostly; #endif @@ -158,7 +159,9 @@ void __init 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.31.1