From nobody Fri May 17 11:05:34 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.com; dkim=pass; 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 ARC-Seal: i=1; a=rsa-sha256; t=1651871867; cv=none; d=zohomail.com; s=zohoarc; b=He7g3VIvSJ1uktbvvDknrkFff1VbD8JlTZ5Zg6H8OBG1J3+c37AzPEi5jndvpaCllzSpPQT9PX9CX58Jfdfz9Qv/hTcWfQMXSJi1s6YNBKOy0HZQCHqFBQi3YEMSd52vCAiN1la25ISQQnqVNIeBT8pfzIFsPs7gCry+qkCiWik= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1651871867; h=Content-Transfer-Encoding:Cc:Date:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:To; bh=vjFMwkzOm8q8FQjtwUt5drq44ZnFk8LSmvePpqG7hGo=; b=bPQlZkp9MnmYf0fejs1p4Bh/d0qAuKKwX+Y+Itut9qKo6jTUfPiDAZ4d5isGCiTybvb+UXf4A0wLp7wJogFM84Rh8x/MeIPrl6KCuoT4IR4pwC5JATtj5H6G1al5VByGizKQKqLf7TFSOEvsSQ+CVHAvl0dojHxoN6JHpcIdZbY= ARC-Authentication-Results: i=1; mx.zohomail.com; dkim=pass; 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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1651871867197412.2963661142775; Fri, 6 May 2022 14:17:47 -0700 (PDT) Received: from localhost ([::1]:49236 helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1nn5Ka-0008F0-6U for importer@patchew.org; Fri, 06 May 2022 17:17:44 -0400 Received: from eggs.gnu.org ([2001:470:142:3::10]:46580) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1nn1GI-0001wP-Qa for qemu-devel@nongnu.org; Fri, 06 May 2022 12:57:02 -0400 Received: from mail-pl1-x62f.google.com ([2607:f8b0:4864:20::62f]:41955) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_128_GCM_SHA256:128) (Exim 4.90_1) (envelope-from ) id 1nn1GH-0001vw-0W for qemu-devel@nongnu.org; Fri, 06 May 2022 12:57:02 -0400 Received: by mail-pl1-x62f.google.com with SMTP id s14so8000668plk.8 for ; Fri, 06 May 2022 09:57:00 -0700 (PDT) Received: from localhost.localdomain (c-73-222-83-91.hsd1.ca.comcast.net. [73.222.83.91]) by smtp.gmail.com with ESMTPSA id i13-20020a63584d000000b003c14af50606sm3414719pgm.30.2022.05.06.09.56.57 (version=TLS1_3 cipher=TLS_AES_256_GCM_SHA384 bits=256/256); Fri, 06 May 2022 09:56:58 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=rivosinc-com.20210112.gappssmtp.com; s=20210112; h=from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vjFMwkzOm8q8FQjtwUt5drq44ZnFk8LSmvePpqG7hGo=; b=RBL48KIe5TLOpEE0SbvDMiz0lMejxmT/E0jnrXUCOboW+5LRVV2kA+RHdy5Hm8crs+ TFEtqr9sYbdNOT0w3VJz/3atcZKAsRxEbFwWyoG5rKQkTo4J3V2PbdIX0aKtktERnDRj FoAZ1g/LSh/mS8qmyo/+GHGyyHAO6yjaEk7+vAoEOpxcA+NLb0ir4ClCiNG8DtnMMgEz /ZkTqWuRzBJCm1/5y0R1/TewoOsl9R4dmS0A+Czb9uMToaK94uyWaX6fuCmnxWNtbPuX 11wIZGfs5hRhXzdG+4BpZvFjjEga8JqAX25G4lq1VTsdoKe/bkgvGH/HZw9u0UEkq0fl gxqw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20210112; h=x-gm-message-state:from:to:cc:subject:date:message-id:mime-version :content-transfer-encoding; bh=vjFMwkzOm8q8FQjtwUt5drq44ZnFk8LSmvePpqG7hGo=; b=Dyn/hTT0eA8jtyc4VqkDPPVJu+ZBN2cJjBq9/aCuunNg+wLNIifKmvni/rOguekfhz trgak/3TxU/dmQklsbU84u1cVTz7h9xvrWmI5hCEG8TnhQztiprrNHUYdxm62+V9LTuT NmMJ3uYdKDvo8CXeJSaDpB6wNzH2vTayBy8EVlgiJX4ni4m/0e/oWhTChcPxx1zRXtmo PdVQCU1JVQZcbDLh/Kw1WjmVUQRMc3sXgEG7GyuEwwy3dHeaKf+S3ZMkba0NbIcAQPLW Di+XniTtBbNAB7iby978gCIYBrBTwwXsiMSU9KoB/te8m88UkxR2PWpRxrlUOqb5Ln75 liVg== X-Gm-Message-State: AOAM533L//bsAU1jCdm6x8Qd0r2+NhYxMimzroEqmefWOb0qRMulTpfA OqWaLDh6QF7RCEoU53kkVK6c4/v/sUGxAyMS X-Google-Smtp-Source: ABdhPJx3sBaI9RFfpc9fGMf2QGMz6Ccotxu08qcB+k+0ZOBTK2ZFDtz5FDynCXUosWStnvGLn8aqCQ== X-Received: by 2002:a17:903:1cd:b0:15e:8c4a:c543 with SMTP id e13-20020a17090301cd00b0015e8c4ac543mr4474146plh.126.1651856219049; Fri, 06 May 2022 09:56:59 -0700 (PDT) From: Dylan Reid X-Google-Original-From: Dylan Reid To: qemu-devel@nongnu.org Cc: palmer@dabbelt.com, alistair.francis@wdc.com, bin.meng@windriver.com, Dylan Reid Subject: [PATCH] target/riscv: Fix VS mode hypervisor CSR access Date: Fri, 6 May 2022 16:54:57 +0000 Message-Id: <20220506165456.297058-1-dgreid@rivosinc.com> X-Mailer: git-send-email 2.30.2 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable 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; Received-SPF: pass client-ip=2607:f8b0:4864:20::62f; envelope-from=dylan@rivosinc.com; helo=mail-pl1-x62f.google.com X-Spam_score_int: -18 X-Spam_score: -1.9 X-Spam_bar: - X-Spam_report: (-1.9 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, RCVD_IN_DNSWL_NONE=-0.0001, SPF_HELO_NONE=0.001, SPF_PASS=-0.001, T_SCC_BODY_TEXT_LINE=-0.01 autolearn=ham autolearn_force=no X-Spam_action: no action X-Mailman-Approved-At: Fri, 06 May 2022 17:16:01 -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+importer=patchew.org@nongnu.org Sender: "Qemu-devel" X-ZohoMail-DKIM: pass (identity @rivosinc-com.20210112.gappssmtp.com) X-ZM-MESSAGEID: 1651871868822100001 Content-Type: text/plain; charset="utf-8" VS mode access to hypervisor CSRs should generate virtual, not illegal, instruction exceptions. Don't return early and indicate an illegal instruction exception when accessing a hypervisor CSR from VS mode. Instead, fall through to the `hmode` predicate to return the correct virtual instruction exception. Signed-off-by: Dylan Reid Reviewed-by: Alistair Francis --- target/riscv/csr.c | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/target/riscv/csr.c b/target/riscv/csr.c index 3500e07f92..4ea7df02c9 100644 --- a/target/riscv/csr.c +++ b/target/riscv/csr.c @@ -3141,13 +3141,13 @@ static inline RISCVException riscv_csrrw_check(CPUR= ISCVState *env, #if !defined(CONFIG_USER_ONLY) int effective_priv =3D env->priv; =20 - if (riscv_has_ext(env, RVH) && - env->priv =3D=3D PRV_S && - !riscv_cpu_virt_enabled(env)) { + if (riscv_has_ext(env, RVH) && env->priv =3D=3D PRV_S) { /* - * We are in S mode without virtualisation, therefore we are in HS= Mode. + * We are in either HS or VS mode. * Add 1 to the effective privledge level to allow us to access the - * Hypervisor CSRs. + * Hypervisor CSRs. The `hmode` predicate will determine if access + * should be allowed(HS) or if a virtual instruction exception sho= uld be + * raised(VS). */ effective_priv++; } --=20 2.30.2