From nobody Fri Dec 19 20:59:51 2025 Delivered-To: importer@patchew.org Received-SPF: pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) client-ip=209.51.188.17; envelope-from=qemu-devel-bounces+importer=patchew.org@nongnu.org; helo=lists.gnu.org; Authentication-Results: mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail(p=none dis=none) header.from=wdc.com ARC-Seal: i=1; a=rsa-sha256; t=1575915946; cv=none; d=zohomail.com; s=zohoarc; b=VOt/ZFmqAPLpPuqr1ZfuqI2KyfQjNnyTlT1UnTCxQUJb/VBalOiTAOBdD7soCQ68+aREywX10Ga7dEAkdbpZ+2vME8IX5aJfson+n3RbLanv9WyaQZuVfh1YVcg9EzzE3NkpINGH3VSai5K2AMp06WAJ44W7zCgw3f3iJ4u2XCc= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1575915946; h=Content-Transfer-Encoding:Cc:Date:From:In-Reply-To:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:References:Sender:Subject:To; bh=RDsU38L6hSgLL5QwZTNMW8FHUA/1gwy/svhJ6Q6rs4I=; b=HYx3iWk/LJwGBoJyqy4L2oPokNnB9DXtrF9b4jSqnnCqZya/2HIERWX1LgrDWBplmTd/hwVFj31sbqpbgb+LIZNnQQH5e0T7wrDjgvxQwWAfojzeCxOVXJWPgSTfxO5gEhd9ljWl2MBCQWO9S5JLPySbtQKLi+dqeDT4pYNZ5pA= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=fail header.i=@wdc.com; spf=pass (zohomail.com: domain of gnu.org designates 209.51.188.17 as permitted sender) smtp.mailfrom=qemu-devel-bounces+importer=patchew.org@nongnu.org; dmarc=fail header.from= (p=none dis=none) header.from= Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1575915946455588.487087507731; Mon, 9 Dec 2019 10:25:46 -0800 (PST) Received: from localhost ([::1]:44439 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ieNj6-0002bp-QD for importer@patchew.org; Mon, 09 Dec 2019 13:25:44 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:34569) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ieNaR-0006sw-Gs for qemu-devel@nongnu.org; Mon, 09 Dec 2019 13:16:48 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ieNaQ-0007Ey-BW for qemu-devel@nongnu.org; Mon, 09 Dec 2019 13:16:47 -0500 Received: from esa2.hgst.iphmx.com ([68.232.143.124]:7351) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ieNaQ-000793-38; Mon, 09 Dec 2019 13:16:46 -0500 Received: from h199-255-45-15.hgst.com (HELO uls-op-cesaep02.wdc.com) ([199.255.45.15]) by ob1.hgst.iphmx.com with ESMTP; 10 Dec 2019 02:17:04 +0800 Received: from uls-op-cesaip02.wdc.com ([10.248.3.37]) by uls-op-cesaep02.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 09 Dec 2019 10:11:02 -0800 Received: from risc6-mainframe.sdcorp.global.sandisk.com (HELO risc6-mainframe.int.fusionio.com) ([10.196.158.235]) by uls-op-cesaip02.wdc.com with ESMTP; 09 Dec 2019 10:16:45 -0800 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=wdc.com; i=@wdc.com; q=dns/txt; s=dkim.wdc.com; t=1575915425; x=1607451425; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=FEn9iowGIhh/4J3ieDV3VnOcaKziBmbfgw3ywvga+og=; b=qo1XQQfY5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vOCZ0wsQJ0q3NSYuWFtu5JnztlskbwQgJVoxFCfj OekPcrfUvydO/gm3HIVFx0dmOT6NgThreQRjEPOBw2UxrvxsKL8lJHH4he1d8U2RA84Rn/u15W Z8y2OR6AaM7v1vUAmN6ZBFbWC9TAEpN1m20hCezt98CxhYiYnOaKNVQiphMkxBCA4JZcDIThy0 hUDRD5D7zGfKWBDeA3e7L80XgQi0n9PASPFLzUrqbiZBM8YOmlNZSFbxE0VKdvpkzYgiMwmeQ5 Jk0= WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v1 09/36] target/riscv: Fix CSR perm checking for HS mode Date: Mon, 9 Dec 2019 10:11:04 -0800 Message-Id: <72b377cf058f6d159a40301b6880f017404ef9cd.1575914822.git.alistair.francis@wdc.com> X-Mailer: git-send-email 2.24.0 In-Reply-To: References: MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-detected-operating-system: by eggs.gnu.org: FreeBSD 9.x [fuzzy] X-Received-From: 68.232.143.124 X-BeenThere: qemu-devel@nongnu.org X-Mailman-Version: 2.1.23 Precedence: list List-Id: List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Cc: alistair.francis@wdc.com, palmer@dabbelt.com, alistair23@gmail.com Errors-To: qemu-devel-bounces+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: fail (Header signature does not verify) Content-Type: text/plain; charset="utf-8" Update the CSR permission checking to work correctly when we are in HS-mode. Signed-off-by: Alistair Francis Reviewed-by: Palmer Dabbelt --- target/riscv/csr.c | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 6a0a59edfd..eebfc1823d 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -802,12 +802,22 @@ int riscv_csrrw(CPURISCVState *env, int csrno, target= _ulong *ret_value, =20 /* check privileges and return -1 if check fails */ #if !defined(CONFIG_USER_ONLY) - int csr_priv =3D get_field(csrno, 0x300); + int effective_priv =3D env->priv; int read_only =3D get_field(csrno, 0xC00) =3D=3D 3; - if ((!env->debugger) && (env->priv < csr_priv)) { - return -1; + + if (riscv_has_ext(env, RVH) && + env->priv =3D=3D PRV_S && + !riscv_cpu_virt_enabled(env)) { + /* + * We are in S mode without virtualisation, therefore we are in HS= Mode. + * Add 1 to the effective privledge level to allow us to access the + * Hypervisor CSRs. + */ + effective_priv++; } - if (write_mask && read_only) { + + if ((write_mask && read_only) || + (!env->debugger && (effective_priv < get_field(csrno, 0x300)))) { return -1; } #endif --=20 2.24.0