From nobody Sun May 19 15:43:59 2024 Delivered-To: importer2@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+importer2=patchew.org@nongnu.org; dmarc=pass(p=none dis=none) header.from=syntacore.com ARC-Seal: i=1; a=rsa-sha256; t=1711720012; cv=none; d=zohomail.com; s=zohoarc; b=ToBRWm4rksa7TSCYIp/UzoPUGmoaP68zJpTHUt2sRPijCQQtcjbtWONGvBqv9OoxYD7HkwoML6XCvz5W7yySoBONZQ96suVa6JNZDnAIgcMDTeQY79rLVDHTWvlowVD9BlVgpupFUp8dutqOLrx4pAmJzEFUT95FFPzNapF/tdA= ARC-Message-Signature: i=1; a=rsa-sha256; c=relaxed/relaxed; d=zohomail.com; s=zohoarc; t=1711720012; h=Content-Type:Content-Transfer-Encoding:Cc:Cc:Date:Date:From:From:List-Subscribe:List-Post:List-Id:List-Archive:List-Help:List-Unsubscribe:MIME-Version:Message-ID:Sender:Subject:Subject:To:To:Message-Id:Reply-To; bh=24Hng9VXJ0njl4818EF1rbSl5XhF0Y9Qr9hcIhgmEZE=; b=c8GhJ5gWkkgs9KRF4zlLcsmyWZShuXwbnNT4SwuoBxhVB6JgtwUfjMErtY/sf2CN5dBRT8JLxGgtWPLOG6EKm4LUKDLgTXIhFyOpIruUnAxHjMSvLI1F3wP7rCJAVXni3CaoIGmiH2N5Rwnda1wI4P6KMzC2BBJ8/wvZUO+WMKU= 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+importer2=patchew.org@nongnu.org; dmarc=pass header.from= (p=none dis=none) Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1711720012171834.9141187655418; Fri, 29 Mar 2024 06:46:52 -0700 (PDT) Received: from localhost ([::1] helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1rqCYG-0007TN-10; Fri, 29 Mar 2024 09:45:48 -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 1rqCYD-0007S6-IJ; Fri, 29 Mar 2024 09:45:46 -0400 Received: from mta-04.yadro.com ([89.207.88.248]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1rqCYB-000448-PB; Fri, 29 Mar 2024 09:45:45 -0400 DKIM-Filter: OpenDKIM Filter v2.11.0 mta-04.yadro.com 452CEC0006 DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syntacore.com; s=mta-04; t=1711719936; bh=24Hng9VXJ0njl4818EF1rbSl5XhF0Y9Qr9hcIhgmEZE=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=ggiSImtpsMv0wnuwXIVQQyDjNEaHaon9X/SYJC3fZewZEOVIj7RNxH0iI54nroJxC tCG3jbG+njJB3ZGbOzYGt9zjz2pdbTPvDoKuIoFXyKlOwC8k9106l1C3U0kob/f/NF gzV8IQ18D+yZwpvpywEtp3qrgihq7Ohj4qsVZE4AXtYCK4/gWU+9WuLNZnCCKtvCj2 ghVPOdcPwqU0bPH2w9pT1T8q6n2xLN3FDCX5UfNpBxCjhMBrN0DF9aB5S1uIcTm+xq mX5WYKhDJADw+b3mNCE/ROObOgutmuMvqkQixVQa+eN/PLRNJVvOJ2biXsgwMi/ArX dqp6MNPTiojDQ== DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=syntacore.com; s=mta-03; t=1711719936; bh=24Hng9VXJ0njl4818EF1rbSl5XhF0Y9Qr9hcIhgmEZE=; h=From:To:Subject:Date:Message-ID:MIME-Version:Content-Type:From; b=CFPMXEJTBiEPkyY7aIIVxVgkeUAIFAWaHp96zfCmqNtEkErI4sXpuuKf7PIOxMOo9 ZaXPpvmiSDcxigCiUnaZmN7TMeITrUVcatGxtp/G5Yaw+AWb1oDK6TzTPtAHonYpWx COvtN/aKW3y1sJc8u/Gk8M3bcvMJ81qgPA5UtV9snfAWl3ITTTUThxicFdazrWhmBP Ap0ZFhSuFw2dMlOZikmF0gXCEpbzJHWg22DUGwjko+YkKQJkYWpgLAC3eCFq2vdsUd rIKHezkhVtV1vgVFecXIDQnD47oJbMxo5GfKfypMBP+Ks9xrwzidy8mbcaeUBBrTP3 uNAFj/SplxOmA== From: Alexei Filippov To: , , , , , CC: , , Alexei Filippov Subject: [PATCH] target/riscv/cpu_helper.c: fix wrong exception raise Date: Fri, 29 Mar 2024 16:45:27 +0300 Message-ID: <20240329134527.1570936-1-alexei.filippov@syntacore.com> X-Mailer: git-send-email 2.34.1 MIME-Version: 1.0 Content-Transfer-Encoding: quoted-printable X-ClientProxiedBy: T-EXCH-07.corp.yadro.com (172.17.11.57) To T-EXCH-12.corp.yadro.com (172.17.11.143) 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+importer2=patchew.org@nongnu.org; helo=lists.gnu.org; Received-SPF: permerror client-ip=89.207.88.248; envelope-from=alexei.filippov@syntacore.com; helo=mta-04.yadro.com X-Spam_score_int: -20 X-Spam_score: -2.1 X-Spam_bar: -- X-Spam_report: (-2.1 / 5.0 requ) BAYES_00=-1.9, DKIM_SIGNED=0.1, DKIM_VALID=-0.1, DKIM_VALID_AU=-0.1, DKIM_VALID_EF=-0.1, SPF_HELO_NONE=0.001, T_SPF_PERMERROR=0.01 autolearn=ham autolearn_force=no X-Spam_action: no action 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+importer2=patchew.org@nongnu.org Sender: qemu-devel-bounces+importer2=patchew.org@nongnu.org X-ZohoMail-DKIM: pass (identity @syntacore.com) (identity @syntacore.com) X-ZM-MESSAGEID: 1711720018223100001 Content-Type: text/plain; charset="utf-8" Successed two stage translation, but failed pmp check can cause guest page fault instead of regular page fault. In case of execution ld instuction in VS mode we can face situation when two stages of translation was passed successfully, and if PMP check was failed first_stage_error variable going to be setted to false and raise_mmu_exception will raise RISCV_EXCP_LOAD_GUEST_ACCESS_FAULT(scause =3D=3D 21) instead of RISCV_EXCP_LOAD_ACCESS_FAULT(scause =3D=3D 5) and this is wrong, according to RISCV privileged spec sect. 3.7: Attempting to execute a load or load-reserved instruction which accesses a physical address within a PMP region without read permissions raises a load access-fault exception. Signed-off-by: Alexei Filippov --- target/riscv/cpu_helper.c | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index bc70ab5abc..eaef1c2c62 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1408,9 +1408,7 @@ bool riscv_cpu_tlb_fill(CPUState *cs, vaddr address, = int size, __func__, pa, ret, prot_pmp, tlb_size); =20 prot &=3D prot_pmp; - } - - if (ret !=3D TRANSLATE_SUCCESS) { + } else { /* * Guest physical address translation failed, this is a HS * level exception --=20 2.34.1