From patchwork Mon Jul 1 02:25:53 2024 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Jiayi Li X-Patchwork-Id: 13717566 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 lists.gnu.org (lists.gnu.org [209.51.188.17]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by smtp.lore.kernel.org (Postfix) with ESMTPS id 48B17C2BD09 for ; Mon, 1 Jul 2024 05:41:54 +0000 (UTC) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sO9mj-0001CL-3H; Mon, 01 Jul 2024 01:41:05 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sO6kA-0006ar-Qf for qemu-devel@nongnu.org; Sun, 30 Jun 2024 22:26:14 -0400 Received: from azure-sdnproxy.icoremail.net ([20.231.56.155]) by eggs.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sO6k8-00032h-TR for qemu-devel@nongnu.org; Sun, 30 Jun 2024 22:26:14 -0400 Received: from E0005096DT.eswin.cn (unknown [10.64.112.173]) by app1 (Coremail) with SMTP id TAJkCgDHWuK3E4JmOcQSAA--.23755S4; Mon, 01 Jul 2024 10:26:02 +0800 (CST) From: Jiayi Li To: qemu-devel@nongnu.org, bmeng.cn@gmail.com, dbarboza@ventanamicro.com, luweu1518@gmail.com, zhiwei_liu@linux.alibaba.com Cc: lijiayi@eswincomputing.com Subject: [PATCH] target/riscv: Validate the mode in write_vstvec Date: Mon, 1 Jul 2024 10:25:53 +0800 Message-Id: <20240701022553.1982-1-lijiayi@eswincomputing.com> X-Mailer: git-send-email 2.39.2.windows.1 MIME-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UDUUUUU= X-CM-SenderInfo: 5olmxt11l6v25zlqu0xpsx3x1qjou0bp/ Received-SPF: pass client-ip=20.231.56.155; envelope-from=lijiayi@eswincomputing.com; helo=azure-sdnproxy.icoremail.net X-Spam_score_int: -25 X-Spam_score: -2.6 X-Spam_bar: -- X-Spam_report: (-2.6 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_LOW=-0.7, RCVD_IN_MSPIKE_H4=-0.01, RCVD_IN_MSPIKE_WL=-0.01, SPF_HELO_NONE=0.001, SPF_PASS=-0.001 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Mon, 01 Jul 2024 01:41:02 -0400 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Errors-To: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Sender: qemu-devel-bounces+qemu-devel=archiver.kernel.org@nongnu.org Base on the riscv-privileged spec, vstvec substitutes for the usual stvec. Therefore, the encoding of the MODE should also be restricted to 0 and 1. Signed-off-by: Jiayi Li Reviewed-by: Alistair Francis Reviewed-by: LIU Zhiwei --- target/riscv/csr.c | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 432c59dc66..f9229d92ab 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -3791,7 +3791,12 @@ static RISCVException read_vstvec(CPURISCVState *env, int csrno, static RISCVException write_vstvec(CPURISCVState *env, int csrno, target_ulong val) { - env->vstvec = val; + /* bits [1:0] encode mode; 0 = direct, 1 = vectored, 2 >= reserved */ + if ((val & 3) < 2) { + env->vstvec = val; + } else { + qemu_log_mask(LOG_UNIMP, "CSR_VSTVEC: reserved mode not supported\n"); + } return RISCV_EXCP_NONE; }