From nobody Tue Feb 10 14:42:35 2026 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1580519633608978.7710970274713; Fri, 31 Jan 2020 17:13:53 -0800 (PST) Received: from localhost ([::1]:34282 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ixhM8-0000zU-9e for importer@patchew.org; Fri, 31 Jan 2020 20:13:52 -0500 Received: from eggs.gnu.org ([2001:470:142:3::10]:56626) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1ixhH1-0000zS-BU for qemu-devel@nongnu.org; Fri, 31 Jan 2020 20:08:36 -0500 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1ixhH0-0006CU-DL for qemu-devel@nongnu.org; Fri, 31 Jan 2020 20:08:35 -0500 Received: from esa4.hgst.iphmx.com ([216.71.154.42]:17129) by eggs.gnu.org with esmtps (TLS1.0:DHE_RSA_AES_256_CBC_SHA1:32) (Exim 4.71) (envelope-from ) id 1ixhH0-00069K-3X; Fri, 31 Jan 2020 20:08:34 -0500 Received: from h199-255-45-14.hgst.com (HELO uls-op-cesaep01.wdc.com) ([199.255.45.14]) by ob1.hgst.iphmx.com with ESMTP; 01 Feb 2020 09:08:33 +0800 Received: from uls-op-cesaip01.wdc.com ([10.248.3.36]) by uls-op-cesaep01.wdc.com with ESMTP/TLS/ECDHE-RSA-AES256-GCM-SHA384; 31 Jan 2020 17:01:42 -0800 Received: from risc6-mainframe.sdcorp.global.sandisk.com (HELO risc6-mainframe.int.fusionio.com) ([10.196.158.235]) by uls-op-cesaip01.wdc.com with ESMTP; 31 Jan 2020 17:08:33 -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=1580519313; x=1612055313; h=from:to:cc:subject:date:message-id:in-reply-to: references:mime-version:content-transfer-encoding; bh=cmLzQpUoUHVRHXGrA7b8U45rElR7fLzQ2/9P3hAehNM=; b=VLSo/fu9yJx7GqQUucu121MkbLw2c0diqseVYUMTGf691HCkd3BliMtz EbDaqeg7DWox9aqeeXT+B3IT9koLjKW3sQM1H7TOkF+KLjckgOf9Zw7bE deJRPyLLH2M7Tnh71vAZAsWRG89KoP52YGcJBJA2/7wweycGxljNK3sMH 3TsqnASLwSTgPYEPZp1WtMliXIAIlIxlCot1rua1JaOr6ElwFkclULQkk SvozSFKGlZieTzc99IJuBtymnowLzszHQRv0in/KYh8HLTPANB6/87mMW kOiFjVdiDV+pTXQkQM9sV5P9zQ8pxR5dVb/CnngLWZ/Oag9QlOe4ctzAF A==; IronPort-SDR: x3x5BpWiR1aBk9v98dn5z9kf3JnoXGY2QJsbEixXJdoFy//t8227XNUFjyhSrpridTYz8VeWCe vDfn7Ix1t2g29zjcxnZPRNpgnss0fZmpllMvrRMcANDa7bjuStCqol1m8tbGuNYWflki//l3cA FgfFqH66kei1CxLs2bTjHVv36ylOZVJeGc5ZIrEjZPFHChLMIVi3ubMDwS9rr0hHhOwj9CySMD KcxWG3KfIaY8lbPyZxPFqAwQrjDsprdI9voi65xCkiModh0rCF/bPAVduSArtUdVUCgO09IRjT VXQ= X-IronPort-AV: E=Sophos;i="5.70,388,1574092800"; d="scan'208";a="128872422" IronPort-SDR: rBz1BYKFbPS1f3ILpzmrPAZvyDv4wIT7IlFC1xyMIVkzZvufxpZQQOHRVBgq3EILWJB+GCGF8o RXTOqVDM92OVWM//yp9+G6cXtx71Yii3aoeTNssx0LhPnuaqKDoWCOayfY7rSzAMVSyXvxWriO ghv9g4ewZSSbdmpLXxvjmiZBL0mTwuamcVUU74/JczRAVWdC5em/1u6wFtFdYPCO2b6wizPkuG DaQ993Wjkgt7v3xdLIqG69/e7yDd+Lyi/wPuhFj6TGYOwot4fNnJTGfk/x7wKFoH3MrLsXQyBK A3r8fHLCWUIoIh17u/uQjVkA IronPort-SDR: +E+ewVnSIc0LQHYZH2IZZkWoLvi/273mf4ESsbMWXG5WMp4lENOiawL9/lZuUVdgo5q+3Gpzg7 +yy+Nty10AUL+w4SEsgY0clcD+n3hjsNYJQP+QjbbRH4YFsCBs/tC/TwGeNbwKntTFzvqLSVp0 VbeM8D8WBSJeTUAvunVGGGaSBVB/EBNhux2nYKxSDTgsr0f2hmBP8t9dWxatI0hLLMPOE2Tald okjYRAYKotc+K7Dwk0c1olDJLoOZD/AWEyhcCdgSGr2xxgGWo9p/IiSvY6KHCgDRXPRQOff83L 9UE= WDCIronportException: Internal From: Alistair Francis To: qemu-devel@nongnu.org, qemu-riscv@nongnu.org Subject: [PATCH v2 08/35] target/riscv: Fix CSR perm checking for HS mode Date: Fri, 31 Jan 2020 17:01:56 -0800 Message-Id: X-Mailer: git-send-email 2.25.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: 216.71.154.42 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 ca27359c7e..c63b2f980c 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -801,12 +801,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.25.0