From patchwork Fri Apr 14 15:58:28 2023 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andy Chiu X-Patchwork-Id: 13211750 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.4.0 (2014-02-07) on aws-us-west-2-korg-lkml-1.web.codeaurora.org Received: from vger.kernel.org (vger.kernel.org [23.128.96.18]) by smtp.lore.kernel.org (Postfix) with ESMTP id 3B685C77B72 for ; Fri, 14 Apr 2023 15:59:28 +0000 (UTC) Received: (majordomo@vger.kernel.org) by vger.kernel.org via listexpand id S230399AbjDNP71 (ORCPT ); Fri, 14 Apr 2023 11:59:27 -0400 Received: from lindbergh.monkeyblade.net ([23.128.96.19]:44252 "EHLO lindbergh.monkeyblade.net" rhost-flags-OK-OK-OK-OK) by vger.kernel.org with ESMTP id S230418AbjDNP7Y (ORCPT ); Fri, 14 Apr 2023 11:59:24 -0400 Received: from mail-pl1-x62c.google.com (mail-pl1-x62c.google.com [IPv6:2607:f8b0:4864:20::62c]) by lindbergh.monkeyblade.net (Postfix) with ESMTPS id 619CCB453 for ; Fri, 14 Apr 2023 08:59:22 -0700 (PDT) Received: by mail-pl1-x62c.google.com with SMTP id i8so9741409plt.10 for ; Fri, 14 Apr 2023 08:59:22 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=sifive.com; s=google; t=1681487962; x=1684079962; h=references:in-reply-to:message-id:date:subject:cc:to:from:from:to :cc:subject:date:message-id:reply-to; bh=PRENwq6Q5h6bJkuLEU9y2ZlvRnSbbBagGQhAGvyqbY8=; b=eV93yDj+Cvno/AR2Kqbp7T2X+jNoQ0r1Gm5oWicJqdZQBTQoW8zQMKqcIu2ZK8qm57 YoSs3FvjzFcpICELt84PzxQLl7L6iEzZDv2cSCM1UpETOR3hDXewrSMOXeN/pvUS7+vt az6AEvDKtT2we5KD8H70GqYRlIflTmBjlxHUXJzxoAtBAGccGgMeu3RHIPxnJ2mhY2gh sJEyNWIXhgUDw6a5s9dhisff3Oly8G524Sc9mjCiJo/+5D1d0oE1rb4ks4yexgrIPG/h yRf8TxjynIs9s7HbwQiOJKJTCT6LCUkJ160ZyoZhNugeH1DsgnQtMaoRp2StX6kS/Xxc 07bg== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20221208; t=1681487962; x=1684079962; h=references:in-reply-to:message-id:date:subject:cc:to:from :x-gm-message-state:from:to:cc:subject:date:message-id:reply-to; bh=PRENwq6Q5h6bJkuLEU9y2ZlvRnSbbBagGQhAGvyqbY8=; b=Ecx7uIgXFiCo4fWfKHqd5A4Iq4DspNrXZ8w2xJQfDVg5P1lAbQmmtPXPnO6nfJPNly ZqP41he4xCuwmPWyZU0WRgb8PHY4CJKRtWveS0HVyN8Fpis2hcit2CzrG4W6mCKXzE49 7aaEb7rdqkRS2J2AAyFl8P2I+w7a2jMYSAA85yGB9QiEjWU3p4pRXnQUYG49HTVCrLEm wGAAbZy85OzHie5icRGrt0r7Lmzvk1+FV+NIzFChikKEc1n3LY/z/GdjYmmKVtCaadcp f6fwAVW0qy/wNZQhJK1RfDWpWiPiNkActbKHrCxoepReIHXfC5bJHIXlpBn0zg0dPn0A GujA== X-Gm-Message-State: AAQBX9fwYnIjTugBWh51jnOjvIO49GMyoJCrMIv2HUkbrsCMtfJ4u8YX IVFAKviIBujZsoJbG9zAItrOww== X-Google-Smtp-Source: AKy350YHJaKAhtMi3NPY+rjWgsiPejyppDLmmbC6OaSfsoWJPScFQLerfIgZudmYoZqZM1BdigvDvA== X-Received: by 2002:a17:90b:1e0a:b0:246:ac68:d4e9 with SMTP id pg10-20020a17090b1e0a00b00246ac68d4e9mr6316947pjb.6.1681487961697; Fri, 14 Apr 2023 08:59:21 -0700 (PDT) Received: from hsinchu25.internal.sifive.com (59-124-168-89.hinet-ip.hinet.net. [59.124.168.89]) by smtp.gmail.com with ESMTPSA id br8-20020a17090b0f0800b00240d4521958sm3083584pjb.18.2023.04.14.08.59.17 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 14 Apr 2023 08:59:21 -0700 (PDT) From: Andy Chiu To: linux-riscv@lists.infradead.org, palmer@dabbelt.com, anup@brainfault.org, atishp@atishpatra.org, kvm-riscv@lists.infradead.org, kvm@vger.kernel.org Cc: vineetg@rivosinc.com, greentime.hu@sifive.com, guoren@linux.alibaba.com, Vincent Chen , Han-Kuan Chen , Andy Chiu , Paul Walmsley , Albert Ou , Guo Ren , Jisheng Zhang , Nicolas Saenz Julienne , =?utf-8?b?QmrDtnJuIFTDtnBl?= =?utf-8?b?bA==?= , Frederic Weisbecker , Andrew Bresticker , Heiko Stuebner , Conor Dooley , Masahiro Yamada , Alexandre Ghiti Subject: [PATCH -next v18 05/20] riscv: Disable Vector Instructions for kernel itself Date: Fri, 14 Apr 2023 15:58:28 +0000 Message-Id: <20230414155843.12963-6-andy.chiu@sifive.com> X-Mailer: git-send-email 2.17.1 In-Reply-To: <20230414155843.12963-1-andy.chiu@sifive.com> References: <20230414155843.12963-1-andy.chiu@sifive.com> Precedence: bulk List-ID: X-Mailing-List: kvm@vger.kernel.org From: Guo Ren Disable vector instructions execution for kernel mode at its entrances. 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 Signed-off-by: Vineet Gupta Signed-off-by: Andy Chiu Reviewed-by: Conor Dooley Reviewed-by: Heiko Stuebner Tested-by: Heiko Stuebner --- arch/riscv/kernel/entry.S | 6 +++--- arch/riscv/kernel/head.S | 12 ++++++------ 2 files changed, 9 insertions(+), 9 deletions(-) diff --git a/arch/riscv/kernel/entry.S b/arch/riscv/kernel/entry.S index 3fbb100bc9e4..e9ae284a55c1 100644 --- a/arch/riscv/kernel/entry.S +++ b/arch/riscv/kernel/entry.S @@ -48,10 +48,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_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 3fd6a4bd9c3e..e16bb2185d55 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_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_VS csrc CSR_STATUS, t0 #ifdef CONFIG_RISCV_BOOT_SPINWAIT