From nobody Mon Nov 25 05:31:09 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 1717804847385798.221389850228; Fri, 7 Jun 2024 17:00:47 -0700 (PDT) Received: from [::1] (helo=lists1p.gnu.org) by lists.gnu.org with esmtp (Exim 4.90_1) (envelope-from ) id 1sFf5q-0004m6-CG; Fri, 07 Jun 2024 15:17:42 -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 1sFf5o-0004lq-Pc; Fri, 07 Jun 2024 15:17:40 -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 1sFf5n-00033v-4R; Fri, 07 Jun 2024 15:17:40 -0400 Received: from tsrv.corpit.ru (tsrv.tls.msk.ru [192.168.177.2]) by isrv.corpit.ru (Postfix) with ESMTP id ACBF36E56C; Fri, 7 Jun 2024 22:14:54 +0300 (MSK) Received: from tls.msk.ru (mjt.wg.tls.msk.ru [192.168.177.130]) by tsrv.corpit.ru (Postfix) with SMTP id DF965E2765; Fri, 7 Jun 2024 22:13:59 +0300 (MSK) Received: (nullmailer pid 529462 invoked by uid 1000); Fri, 07 Jun 2024 19:13:58 -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-9.0.1 62/71] target/riscv: do not set mtval2 for non guest-page faults Date: Fri, 7 Jun 2024 22:13:43 +0300 Message-Id: <20240607191356.529336-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: 1717804849321100001 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 e3a7797d00..484edad900 100644 --- a/target/riscv/cpu_helper.c +++ b/target/riscv/cpu_helper.c @@ -1375,17 +1375,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