Received: by 2002:a05:6a10:8395:0:0:0:0 with SMTP id n21csp362048pxh; Tue, 9 Nov 2021 11:57:09 -0800 (PST) X-Google-Smtp-Source: ABdhPJyphbGgodBcUhZfxV1I3poPdtAAed39I4Y2o9LKRLDYrHBz6opPg7EaUIxqS6BoYwIif+/G X-Received: by 2002:a05:6e02:1848:: with SMTP id b8mr6998385ilv.299.1636487828849; Tue, 09 Nov 2021 11:57:08 -0800 (PST) ARC-Seal: i=1; a=rsa-sha256; t=1636487828; cv=none; d=google.com; s=arc-20160816; b=BWwsDeAr65Vx7WU4Sfe9dQqRxB3cFS/Vup0DxW3LPWQcPK9Dj9jceLyv1F8pjGfu02 BireI5SD5o9ea38vgW4cJ9UWolf84Mck0TbIVGgT7h3ttZ+QJnJZ6fA0hcpNUw1S7wHw pgbHG4Yrk7xAy2UnQXQXnFwrzgRlIsN0Vv59n5xzsmDS8pW7mlo8vF2L3IvCzxDF1NSB BOhyENzj/xtQvRlwYY2afujTjk6JZVyUvXBcNknjnKOaqaSVVd9hbpHPnvKXVkEonShx R3R6jFH79SCD8AoaU2FrrQTMGPLAK/k6qbMrYRJqDCkXor5D0szkDp+ZemcuUKSXmYwj rJ2A== 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=QSqFepERE4N2wqVXalvOoo260yooYSe4DI6a5ek1AvE=; b=kW+f0c4uxIjaCz2mUxrvhhvmDrLc8csP/Uvl9VJD9XoO2G4d8y1hkuo1ymBMPljavb z/uP4Zl9EDMExnJWk7e4eoSekZMkssJiBjGtzOzHQRqAKuRPxEp/B1lpSU5S0qGjyAOX BvBhAnpZBXD8KeqXoRQi0/IK3DKI3WntrM2GFiklifkOCkBZDY5QOqUxlspQ5+gmOfam kBYhTzW1YHvv2jRElXAXsAIjgoBl6+Yj6nd5ckvI9rx/OCBKF+zosJbNAlxdGkrSscIn 7BFW1dmcL8SCNXP6M4LJBarIusqOAwJnvBFKaymNPOymiED14jHdyoiKO3hCDc3AdcX4 rNPg== ARC-Authentication-Results: i=1; mx.google.com; dkim=pass header.i=@sifive.com header.s=google header.b="bb5tQb/6"; 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 x22si45691330jat.17.2021.11.09.11.56.42; Tue, 09 Nov 2021 11:57:08 -0800 (PST) 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="bb5tQb/6"; 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 S245032AbhKIJwc (ORCPT + 99 others); Tue, 9 Nov 2021 04:52:32 -0500 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:49274 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S244272AbhKIJvg (ORCPT ); Tue, 9 Nov 2021 04:51:36 -0500 Received: from mail-pf1-x432.google.com (mail-pf1-x432.google.com [IPv6:2607:f8b0:4864:20::432]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 91E6AC061220 for ; Tue, 9 Nov 2021 01:48:43 -0800 (PST) Received: by mail-pf1-x432.google.com with SMTP id 127so18986754pfu.1 for ; Tue, 09 Nov 2021 01:48:43 -0800 (PST) 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=QSqFepERE4N2wqVXalvOoo260yooYSe4DI6a5ek1AvE=; b=bb5tQb/6VeknVaR406cXHwsp0nVG1x2yFyshVKlDcHEmIEaibX4qmuCrnx6r7i3Yzy OWdOraOah9Q6ITGHX4vvFKbZMLJelo1T2DmeZmd5HrSYIJM2iKB3Ls4U8bA0j4091ycA 4dZum9J1j2u00hjCLTf5AADYx9x7fSyilEbPo9Ew+2AjYBoDXSRxEMitnBEGGl7mKqh9 7MLp1wBHB1n4A3S1lWzFu8Xsqhr0mP/L01S7ezDht5Equ+H3qRNPbHZQb9AvS71SHzNv wTxCCUy9H4La495JDszWKYXJl2SRS/rSwWT3Ja+ydDocytajLMyt6FOsFCpcDoJUQYaw yzPQ== 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=QSqFepERE4N2wqVXalvOoo260yooYSe4DI6a5ek1AvE=; b=DrWDdK9Xvi01uSzA5WW59zqYnwSaN08irWjasdJAK8bbwbP10Ajmhb2psTI+IRmJJd RHouldXdTdgXTYczNXm3gcyUvpJYgHuLQcGXH094xxHcOsGk2qqXYZGO6MBTYwBVzsYd Xwjh4UTe1L6FVqdSDjVfUM62ONhHHwv+98c80I+aITQpurS1ORlRkUnFKebs4hp6avwv DquxApjbBGaRPazUfj8fYPEuB5OqiAJ4SeG3YWxYoOGb3DRbc49obWKkMmZwgcQdlGSd 7q06RGwh1W6EZ+tkdWA1QHrvu615mvt+CyMj0rkFsE1w5TPnUwzGyg6DhVb3gRoBOwaP 4IGQ== X-Gm-Message-State: AOAM531Z2qqbH3lNxkvInwZfKAP6pgeXRFqBKaNf38uVdQSAPic8DcTY YatsPFHeYbPyVHToI4At0GHt6g== X-Received: by 2002:aa7:848a:0:b0:47f:d648:2df4 with SMTP id u10-20020aa7848a000000b0047fd6482df4mr6418681pfn.63.1636451323096; Tue, 09 Nov 2021 01:48:43 -0800 (PST) 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 cv1sm1940511pjb.48.2021.11.09.01.48.41 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Tue, 09 Nov 2021 01:48:42 -0800 (PST) From: Greentime Hu To: palmer@dabbelt.com, paul.walmsley@sifive.com, linux-riscv@lists.infradead.org, linux-kernel@vger.kernel.org, aou@eecs.berkeley.edu Subject: [PATCH v9 07/17] riscv: Reset vector register Date: Tue, 9 Nov 2021 17:48:19 +0800 Message-Id: <8612e69a10235e67fac8a55864e77a4ab8f771ac.1636362169.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 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 --- arch/riscv/kernel/entry.S | 6 +++--- arch/riscv/kernel/head.S | 22 ++++++++++++++++++++-- 2 files changed, 23 insertions(+), 5 deletions(-) diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index 98f502654edd..ad0fa80ada81 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 52c5ff9804c5..551afe1de85e 100644 --- a/arch/riscv/kernel/head.S +++ b/arch/riscv/kernel/head.S @@ -242,10 +242,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 @@ -433,6 +433,24 @@ 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 + vsetvli t1, x0, e8, m8 + 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.31.1