From nobody Mon Nov 25 05:31:58 2024 Delivered-To: importer@patchew.org Authentication-Results: mx.zohomail.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 Return-Path: Received: from lists.gnu.org (lists.gnu.org [209.51.188.17]) by mx.zohomail.com with SMTPS id 1717801872047230.30146560367166; Fri, 7 Jun 2024 16:11:12 -0700 (PDT) Received: from [::1] (helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sFf3B-0004Xw-3f; Fri, 07 Jun 2024 15:14:57 -0400 Received: from [2001:470:142:3::10] (helo=eggs.gnu.org) by lists.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFf39-0004X2-Ba; Fri, 07 Jun 2024 15:14:55 -0400 Received: from isrv.corpit.ru ([86.62.121.231]) by eggs.gnu.org with esmtps (TLS1.2:ECDHE_RSA_AES_256_GCM_SHA384:256) (Exim 4.90_1) (envelope-from ) id 1sFf37-0002CD-OJ; Fri, 07 Jun 2024 15:14:55 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id 931156E54F; Fri, 7 Jun 2024 22:14:05 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id C0D72E274B; Fri, 7 Jun 2024 22:13:10 +0300 (MSK) Received: (nullmailer pid 528743 invoked by uid 1000); Fri, 07 Jun 2024 19:13:08 -0000 From: Michael Tokarev To: qemu-devel@nongnu.org Cc: qemu-stable@nongnu.org, Alexei Filippov , Daniel Henrique Barboza , Alistair Francis , Michael Tokarev Subject: [Stable-8.2.5 38/45] target/riscv: do not set mtval2 for non guest-page faults Date: Fri, 7 Jun 2024 22:12:57 +0300 Message-Id: <20240607191307.528622-18-mjt@tls.msk.ru> X-Mailer: git-send-email 2.39.2 In-Reply-To: References: 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=86.62.121.231; envelope-from=mjt@tls.msk.ru; helo=isrv.corpit.ru X-Spam_score_int: -68 X-Spam_score: -6.9 X-Spam_bar: ------ X-Spam_report: (-6.9 / 5.0 requ) BAYES_00=-1.9, RCVD_IN_DNSWL_HI=-5, 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-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-bounces+importer=patchew.org@nongnu.org X-ZM-MESSAGEID: 1717801872462100001 Content-Type: text/plain; charset="utf-8" From: Alexei Filippov Previous patch fixed the PMP priority in raise_mmu_exception() but we're st= ill setting mtval2 incorrectly. In riscv_cpu_tlb_fill(), after pmp check in 2 s= tage translation part, mtval2 will be set in case of successes 2 stage translati= on but failed pmp check. In this case we gonna set mtval2 via env->guest_phys_fault_addr in context = of riscv_cpu_tlb_fill(), as this was a guest-page-fault, but it didn't and mtv= al2 should be zero, according to RISCV privileged spec sect. 9.4.4: When a guest page-fault is taken into M-mode, mtval2 is written with either zero or guest physical address that faulted, shifted by 2 bits. *For other traps, mtval2 is set to zero...* Signed-off-by: Alexei Filippov Reviewed-by: Daniel Henrique Barboza Reviewed-by: Alistair Francis Message-ID: <20240503103052.6819-1-alexei.filippov@syntacore.com> Cc: qemu-stable Signed-off-by: Alistair Francis (cherry picked from commit 6c9a344247132ac6c3d0eb9670db45149a29c88f) Signed-off-by: Michael Tokarev diff --git a/target/riscv/cpu_helper.c b/target/riscv/cpu_helper.c index cf97c782dd..62dda4f284 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1361,17 +1361,17 @@ 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 */ first_stage_error =3D false; - env->guest_phys_fault_addr =3D (im_address | - (address & - (TARGET_PAGE_SIZE - 1))) >>= 2; + if (ret !=3D TRANSLATE_PMP_FAIL) { + env->guest_phys_fault_addr =3D (im_address | + (address & + (TARGET_PAGE_SIZE - 1))= ) >> 2; + } } } } else { --=20 2.39.2